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.

boolean notation IAR Kickstart c compiler

Intellectual 320 points

Replies: 4

Views: 3819

Hello,

This is a simple question, I looked in all the doc but cannot find the answer.

I like to code  I/O ports  in binary, it is more visual but I cannot find the correct notation.

Hex: 0xa3  binary :  0b10100011  , the b generates an error, what is the correct symbol?

stdbool.h is included.

Thanks

4 Replies

  • Unfortunately, the 'C' programming language does not provide a binary notation.

    This has nothing to do with IAR or MSP430 - it is the standard 'C' language.

    A bit of googling (and searching this site) will turn up plenty of macro tricks, if you want, but it is generally far better to define symbolic symbols with meaningful names for the bits and bit patterns that you need...

  • ClaudeArpin
    This is a simple question, I looked in all the doc but cannot find the answer.

    Well, probably not so a simple quesiton.

    Boolean notation is zero for false and non-zero for true. usually true is defined -1 and false of course 0 then.

    YOu most likely meant "binary notation", and as Andy has explained, thsi is not part of the C standard, even though some few compilers have bothered providing their very own, non-portable, noncompliant notation for binary numbers.

    Tom Torfs has released a nice macro implementation to the public domain.

    His macros basically turn something like

    B8(10010101) into B8_(0x10010101LU) and then do some math on it to return an 8 bit value.

    For 16/32 bit there are B16 (xxxxxxxx,xxxxxxxx) and B32 likewise.

    Comes close.

    Of course you can do

    #define 0b00000000 0
    #define 0b00000001 1
    #define 0b00000010 2
    etc :)

    _____________________________________

    Time to say goodbye - I don't have the time anymore to read and answer forum posts. See my bio for details.

    Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
    I'm sorry that  I can no longer provide help  in the forum or by private conversation.

  • In reply to Jens-Michael Gross:

    Jens-Michael Gross

    Of course you can do

    #define 0b00000000 0
    #define 0b00000001 1
    #define 0b00000010 2
    etc :)

    No - #define symbol names may not begin with a digit!

     

  • In reply to Andy Neil:

    Andy Neil
    No - #define symbol names may not begin with a digit!

    You're right, well, then without the leading zero :)

    But since it takes a few years to type them all in manually, I guess it will never try to compile and therefore nobody will see the error message :)

    After all it was meant as a joke. 64k defines surely won't speed up the compile process.

    _____________________________________

    Time to say goodbye - I don't have the time anymore to read and answer forum posts. See my bio for details.

    Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
    I'm sorry that  I can no longer provide help  in the forum or by private conversation.

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.