IntFromHexStr
IntFromHexStr
Description
Parse a hexadecimal string into an integer. This parser expects hexadecimal digits only and does not accept a 0x prefix.
Aborts on invalid characters.
Parameters
| Name | Direction | Description |
|---|---|---|
hex |
in | Hexadecimal digit string |
Usage example (from documentation)
Int value = IntFromHexStr("deadbeef");Returns
Parsed integer value.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:582:
}
Int IntFromHexStr(const char *hex) {
if (!hex) {
LOG_FATAL("hex is NULL");
const char *hex = "deadbeefcafebabe1234";
Int value = IntFromHexStr(hex);
Str text = IntToHexStr(&value);
bool test_int_from_hex_invalid_digit(void) {
WriteFmt("Testing IntFromHexStr invalid digit handling\n");
IntFromHexStr("12g3"); WriteFmt("Testing IntFromHexStr invalid digit handling\n");
IntFromHexStr("12g3");
return false;
}
bool test_int_from_hex_null(void) {
WriteFmt("Testing IntFromHexStr NULL handling\n");
IntFromHexStr(NULL); WriteFmt("Testing IntFromHexStr NULL handling\n");
IntFromHexStr(NULL);
return false;
}- In
Io.Write.c:626:
Int big_dec = IntFromStr("123456789012345678901234567890");
Int hex_val = IntFromHexStr("deadbeefcafebabe1234");
Int bin_val = IntFromBinary("10100011");
Int oct_val = IntFrom(493);
Last updated on