IntToBinary
Description
Convert an integer to a binary string.
Parameters
| Name | Direction | Description |
|---|---|---|
value |
in | Integer to convert. |
Success
Returns a Str holding the base-2 textual form of value, bound to value’s allocator. value is not modified.
Failure
Returns an empty Str bound to value’s allocator when the underlying IntToStrRadix fails (intermediate allocation failure). The caller cannot distinguish that from a true empty result; use IntTryToStrRadix directly when failure detection is required.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:913:
}
Str IntToBinary(const Int *value) {
return IntToStrRadix(value, 2, false);
}- In
Math.c:117:
IntAdd(&result_value, &a, &b);
text = IntToBinary(&result_value);
bool result = IntToU64(&result_value) == 256;- In
Math.c:1930:
IntAdd(&sum, &ones, &one);
Str bits = IntToBinary(&sum);
bool result = (IntToU64(&sum) == 128u);- In
Convert.c:99:
Int value = IntFrom(13, ALLOCATOR_OF(&alloc));
Str text = IntToBinary(&value);
bool result = IntBitLength(&value) == 4;- In
Convert.c:159:
Int value = IntFromBinary("001011", ALLOCATOR_OF(&alloc));
Str text = IntToBinary(&value);
bool result = IntToU64(&value) == 11;- In
Convert.c:270:
Int zero = IntFromBinary("0", ALLOCATOR_OF(&alloc));
Str text = IntToBinary(&zero);
bool error = true;- In
Read.c:937:
z = "10100011";
StrReadFmt(z, "{b}", bin);
bin_text = IntToBinary(&bin);
success = success && (ZstrCompare(StrBegin(&bin_text), "10100011") == 0);
Last updated on