This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

initialize variable with binary value?

hi all
it may seem very easy but i can't initialize
my code constants with binary value in c51
ver 3.20 franklin DOS version i want to:
code char bin_code[3]={
0b1100110011,0b1111110011,0b1100111011};

but compiler doasn't accept.
any one can help me?

Parents
  • Just write the constants in hex.

    ANSI C does not have any syntax for specifying binary integer literals. Decimal, octal, hex; no binary.

    If Hitech C added an extension to do so -- good for them. The Keil compiler does not happen to have this particular extension.

    As has been noted, the forum already contains a discussion on macro implementations to allow you to write binary constants and transform them into something compilable with standard C.

    ObTrivia: You can't write a literal decimal value for zero in C.

Reply
  • Just write the constants in hex.

    ANSI C does not have any syntax for specifying binary integer literals. Decimal, octal, hex; no binary.

    If Hitech C added an extension to do so -- good for them. The Keil compiler does not happen to have this particular extension.

    As has been noted, the forum already contains a discussion on macro implementations to allow you to write binary constants and transform them into something compilable with standard C.

    ObTrivia: You can't write a literal decimal value for zero in C.

Children
  • "ObTrivia: You can't write a literal decimal value for zero in C."

    don't you mean, "You can't write a literal decimal integer value for zero in C?" ;-)

  • Yep, that's what I meant. (Floats? What's a float?)

    Non-decimal floating point literals could get nightmarish. Maybe 0x12345678.0xdeadbeef isn't so bad, but when you start switching bases on either side of the "radix point", you're asking for headaches.

    Maybe we should break down and just use Ada syntax for numeric literals. Base 11? Go right ahead: 11#48a19. Although even they wimp out and limit the base to be from 2 to 16.