Sometimes fixing a bit twiddling or other low level bug comes down to showing the individual bits. printf does not support printing an integer in radix 2, despite originating from times when code was closer to the metal. The code in reprint is as follows:
/* Print 42 as binary */
reprintf("\f&r", 42);
Octal and hex of course are supported:/* Print 42 as hex */
reprintf("\f$r", 42);
/* Print 42 as octal */
reprintf("\f%r", 42);
These use of '$', '%', and '&' are not entirely arbitrary, as the three characters are sequential in value:
- '$' is 0x24 and selects hexadecimal
- '%' is 0x25 and selects octal
- '&' is 0x26 and selects radix 2 (binary)
- Default output is in decimal
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Binary... How many times did I have to write my own routines to process it ? :-)
Are you sure? yes | no