0

Can I print an integer in binary without additional cycles, conditions, and so on? I know that you can print a number in HEX printf("%x", a) in decimal printf("%d", a) in octal printf("%o", a), but i can't find args for binary. Can you help me?

12 -> 00001100

Sam
  • 17
  • 1
  • 3

1 Answers1

1

First of all, no, printf doesn't provide a formater to print a integer in binary.

Second, do not get fooled. Using printf adds additional cycles. Converting an integer to a string (displaying it as decimal, hexadecimal, binary or other) takes some operations. In the case of binary, it's just that you have to do the conversion for printf and provide it the string containing the binary representation.

Julien Thierry
  • 651
  • 4
  • 11