This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2553: why is hex supported and binary not

Part Number: MSP430G2553

Tool/software: Code Composer Studio

i actually dont understand why hex is supported and binary not

example:

P1DIR |= 0b00000001;   // i get a compiler error >> #19 extra text after expected end of number

P1DIR |= 0x01; // works fine actually

i dont rly want to #define every single binary i use

2.) i heard about some boost-binary header which would support something like this:

P1DIR |= BOOST_BINARY(00000001);

does someone know about the header i could use?

  • What version of the MSP430 compiler do you use?  Recent versions of the compiler support the 0b prefix for binary constants.

    Thanks and regards,

    -George

  • i use the the code compose studio 5.5
    well i also could write a algorithm in C# that write a header file for me for8 or 16bit which would include

    #define b000_0000 0
    #define b000_0001 1
    #define b000_0010 2
    ... and so on
    thats no problem actually

    well curiouse part about this is that im also able to use "P1DIR | = (BIT0 | BIT6)" which stands for "P1DIR |= 0x65" or "P1DIR |= 65"
    and also should stand for "P1DIR |= 0b01000001" but somehow this is just not supported
    this causes some synthax "fog" of understanding the syntax

    keep in mind that 0b00000000 is already defined i the msp430.h header file

    so when i would use :
    #define b0100_0001 65
    P1DIR |= b0100_0001
    this works, and this is the reasonw hy a custom binary.h header file would work

    next time ill just try using:
    #define b0100_0001 0b01000001
    P1DIR |= 0b0100_0001
    and see if this actually works.
    ill document here what that led to

    sincerely

  • A binary constant must begin with the prefix "0b" or "0B".  After that it can only have the characters 0 or 1.  No other characters are allowed.  In particular, any token that begins with the letter "b" is considered an identifier, and not a literal constant.

    Thanks and regards,

    -George

  • Just a note. the 0b binary syntax was a gcc extension and not a part of the standard language until recently.