I'm trying to pull

printf("%d",0010 ); 

but displays 8. How can I output 0010?

  • one
    Himself, pens - avp
  • Is it possible to display @avp without conversion in this wonderful language? Or do you need each character to process and display? - Qada 5:46 pm
  • 0010 is not a binary number in the syntax C - andreymal
  • printf("%s", "0010"); , not? - AnT pm
  • one
    @Qada: For utilitarian purposes, the place of binary output in the C language is hex output. If you need all this "for business", then use hexadecimal. If you need a binary one (for "the task is such"), then yes - "process and output each character." - AnT 6:09 pm

1 answer 1

You give printf octal number 10 and ask to print it as a decimal. You get 8 - did you wait for something else?

There is no format specification for outputting binary numbers, so they must be output manually. As an example:

 // Вывод байта в двоичном виде typedef unsigned char byte; int main() { byte b = 93; // Или любое другое for (int i = 0; i < 8; i++) { printf("%c", (b & 0x80) ? '1' : '0'); b <<= 1; } printf("\n"); return 0; }