As we all know, C in eight, decimal and hexadecimal can be easily implemented through%d,%o and%x, but only does not provide a fast way of binary output. Bo Master sorted out two kinds of simple implementation methods for reference. Method One: itoa function
The Itoa function converts a numeric value to a string and implements it by a specified conversion. (or use C to bring the code block HH)
#include <stdio.h>
#include <stdlib.h>
//Note You must call the Stdlib.h function library
int main (void) {
int a=1000;
Char str[30];
Itoa (a,str,2);//2 is the conversion to 2-in-system
printf ("%s", str);
return 0;
Method Two: Short division
Short division, converting decimal to binary written calculation process is accomplished by simple code. There's no shortcut.
#include <stdio.h>
int main (void) {
int a,b,k,i;
int remainder[30];
A remainder array is defined to collect the remainder of the short division and the reverse output of the stack.
a=1000;
k=0;
while (a!=0) {
b=a/2;
k++;
remainder[k]=a-b*2;
A=A/2;
};
for (i=k;i>=1;i--) {
printf ("%d", Remainder[i]);
return 0;