printf is a formatted output function that can print directly decimal, octal, hexadecimal, output control characters%d,%o,%x, but it does not exist binary, if output binary, can be handwritten, But you can also call the Itoa function inside Stdlib.h, which is not a function in the standard library, but most compilers have this function, so let's introduce
The prototype of the ITOA function is char* itoa (int value, char * string, int radix); int value is converted to an integer, char *string converted into a stored character array int radix converted to a number, such as 2,8,10,16,
Here is the test program:
1#include <stdio.h>2#include <stdlib.h>3 4 intMain ()5 {6 7 intA = A;8printf"octal --%o\n", a);9printf"Hex --%x\n", a);Tenprintf"decimal --%d\n", a); One Chars[Ten]; AItoa (A, S,2); -printf"binary --%s\n", s); -Itoa (A, S,3); theprintf"Triple ---%s\n", s); - return 0; -}
printf usage Print 2 binary, octal, decimal, hex