IntFromBinary
IntFromBinary
Description
Parse a binary string into an integer. Accepts an optional 0b or 0B prefix.
Parameters
| Name | Direction | Description |
|---|---|---|
binary |
in | Binary digit string |
Usage example (from documentation)
Int value = IntFromBinary("0b101101");Returns
Parsed integer value.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:544:
}
Int IntFromBinary(const char *binary) {
if (!binary) {
LOG_FATAL("binary is NULL");- In
Int.Convert.c:90:
WriteFmt("Testing Int binary round trip\n");
Int value = IntFromBinary("001011");
Str text = IntToBinary(&value); WriteFmt("Testing IntCompare leading-zero normalization\n");
Int lhs = IntFromBinary("0001011");
Int rhs = IntFrom(11); WriteFmt("Testing Int zero binary conversion\n");
Int zero = IntFromBinary("0");
Str text = IntToBinary(&zero); WriteFmt("Testing Int binary prefix and separators\n");
Int value = IntFromBinary("0b1010_0011");
bool result = IntToU64(&value) == 163;
bool test_int_from_binary_invalid_digit(void) {
WriteFmt("Testing IntFromBinary invalid digit handling\n");
IntFromBinary("10a1"); WriteFmt("Testing IntFromBinary invalid digit handling\n");
IntFromBinary("10a1");
return false;
}
bool test_int_from_binary_null(void) {
WriteFmt("Testing IntFromBinary NULL handling\n");
IntFromBinary(NULL); WriteFmt("Testing IntFromBinary NULL handling\n");
IntFromBinary(NULL);
return false;
}- In
Int.Compare.c:16:
Int a = IntFrom(41);
Int b = IntFrom(42);
Int c = IntFromBinary("000101010");
bool result = IntCompare(&a, &b) < 0;- In
Int.Compare.c:33:
Int a = IntFrom(41);
Int b = IntFrom(42);
Int c = IntFromBinary("000101010");
bool result = IntLT(&a, &b);- In
Int.Compare.c:54:
Int value = IntFrom(42);
Int same = IntFromBinary("00101010");
Int big = IntFrom(1);- In
Io.Write.c:627:
Int big_dec = IntFromStr("123456789012345678901234567890");
Int hex_val = IntFromHexStr("deadbeefcafebabe1234");
Int bin_val = IntFromBinary("10100011");
Int oct_val = IntFrom(493);- In
Int.Access.c:21:
WriteFmt("Testing IntBitLength\n");
Int value = IntFromBinary("00101000");
bool result = IntBitLength(&value) == 6;- In
Int.Access.c:32:
WriteFmt("Testing IntByteLength\n");
Int value = IntFromBinary("0001001000110100");
bool result = IntByteLength(&value) == 2;- In
Int.Access.c:114:
WriteFmt("Testing IntTrailingZeroCount\n");
Int value = IntFromBinary("1010000");
Int zero = IntInit();- In
Int.Math.c:78:
WriteFmt("Testing IntShiftRight\n");
Int value = IntFromBinary("110000");
IntShiftRight(&value, 4);- In
Int.Type.c:26:
WriteFmt("Testing IntClear\n");
Int value = IntFromBinary("101101");
IntClear(&value);- In
Int.Type.c:40:
WriteFmt("Testing IntClone\n");
Int original = IntFromBinary("1011");
Int clone = IntClone(&original);
Last updated on