C++ Builder 参考手册 ➙ System::Sysutils ➙ IntToHex
整数值转16进制字符串
头文件:#include <System.SysUtils.hpp>
命名空间:System::Sysutils
函数原型:
System::UnicodeString __fastcall IntToHex(System::Int8 Value);
System::UnicodeString __fastcall IntToHex(System::Byte Value);
System::UnicodeString __fastcall IntToHex(short Value);
System::UnicodeString __fastcall IntToHex(System::Word Value);
System::UnicodeString __fastcall IntToHex(int Value);
System::UnicodeString __fastcall IntToHex(unsigned Value);
System::UnicodeString __fastcall IntToHex(__int64 Value);
System::UnicodeString __fastcall IntToHex(unsigned __int64 Value);
System::UnicodeString __fastcall IntToHex(int Value, int Digits);
System::UnicodeString __fastcall IntToHex(__int64 Value, int Digits);
System::UnicodeString __fastcall IntToHex(unsigned __int64 Value, int Digits);
参数:
- Value:整数;
- Digits:最少位数,不足这些位前面补 0;
返回值:
- 参数 Value 转为16进制字符串;
- 只有一个 Value 参数的函数,是按照数据类型,固定位数输出,例如 unsinged char 返回2位16进制数,short 返回4位16进制;
测试发现:char 比较特殊,返回的是8位16进制,但是 signed char 和 unsigned char 都是返回2位16进制数,这说明 char 和 signed char 、unsigned char 都不同,使用时需要注意; - 有 Digits 参数的,最少返回这些位数,不足位数的前面补0,这时第一个参数 Value 只支持 int、__int64和 unsigned __int64,其他类型无法编译通过;
例1:(注释部分无法编译通过)
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Add(IntToHex((char)10));
Memo1->Lines->Add(IntToHex((signed char)10));
Memo1->Lines->Add(IntToHex((unsigned char)10));
Memo1->Lines->Add(IntToHex((short)10));
Memo1->Lines->Add(IntToHex((signed short)10));
Memo1->Lines->Add(IntToHex((unsigned short)10));
// Memo1->Lines->Add(IntToHex((long)10));
// Memo1->Lines->Add(IntToHex((signed long)10));
// Memo1->Lines->Add(IntToHex((unsigned long)10));
Memo1->Lines->Add(IntToHex((int)10));
Memo1->Lines->Add(IntToHex((signed int)10));
Memo1->Lines->Add(IntToHex((unsigned int)10));
Memo1->Lines->Add(IntToHex((long long)10));
Memo1->Lines->Add(IntToHex((signed long long)10));
Memo1->Lines->Add(IntToHex((unsigned long long)10));
Memo1->Lines->Add(L"");
Memo1->Lines->Add(IntToHex(10i8));
Memo1->Lines->Add(IntToHex(10ui8));
Memo1->Lines->Add(IntToHex(10i16));
Memo1->Lines->Add(IntToHex(10ui16));
Memo1->Lines->Add(IntToHex(10i32));
Memo1->Lines->Add(IntToHex(10ui32));
Memo1->Lines->Add(IntToHex(10i64));
Memo1->Lines->Add(IntToHex(10ui64));
Memo1->Lines->Add(IntToHex(10));
Memo1->Lines->Add(IntToHex(10u));
// Memo1->Lines->Add(IntToHex(10l));
// Memo1->Lines->Add(IntToHex(10ul));
Memo1->Lines->Add(IntToHex(10ll));
Memo1->Lines->Add(IntToHex(10ull));
}
运行结果:
运行结果
例2:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Memo1->Lines->Add(IntToHex(200,2));
Memo1->Lines->Add(IntToHex(200,4));
Memo1->Lines->Add(IntToHex(200,6));
Memo1->Lines->Add(IntToHex(200,8));
}
运行结果:
运行结果
相关:
- System::Sysutils::FormatFloat
- System::Sysutils::FloatToStr
- System::Sysutils::FloatToStrF
- System::Sysutils::CurrToStr
- System::Sysutils::CurrToStrF
- System::Sysutils::FormatSettings
- System::Sysutils::TFormatSettings
- System::Sysutils::StrToBool
- System::Sysutils::StrToBoolDef
- System::Sysutils::TryStrToBool
- System::Sysutils::BoolToStr
- System::Sysutils::DateTimeToStr
- System::Sysutils::DateTimeToString
- System::Sysutils::DateToStr
- System::Sysutils::GUIDToString
- System::Sysutils::IntToStr
- System::Sysutils::IntToHex
- System::Sysutils::TimeToStr
- System::Sysutils::UIntToStr
- System::Sysutils
- std::itoa, std::_itoa, std::_itot, std::_itow
- std::ltoa, std::_ltoa, std::_ltot, std::_ltow
- std::ultoa, std::_ultoa, std::_ultot, std::_ultow
- std::_i64toa, std::_i64tot, std::_i64tow
- std::_ui64toa, std::_ui64tot, std::_ui64tow
- std::ecvt, std::_ecvt
- std::fcvt, std::_fcvt
- std::gcvt, std::_gcvt
- <cstdlib>
C++ Builder 参考手册 ➙ System::Sysutils ➙ IntToHex