constant declaration format hex dec bin

hello,

I'm just beginning with Hew and RX210.

I would like to give a binnary value to a variable or constante like this:

#define Cst_1     10100110 (binnary) in place of 0xA6.

is it possible?

if yes in with documentation can I find this information and other type of constant definition.

I see in the same way that in the exemple program renesas never use :

unsigned char or unsigned int but uint8_t, is it explain in a documentation ? All of this type redefinition are their listed in a documentation or in header or c file?

I use the pdg library with the RSKRX210.

thanks for your helps.

Salutations.

  • Hey Vincent,

    Try out:

    #define Cst_1 0b10100110

    This should define Cst_1 as a binary the values specified.

    Regards,

    Anthony Harris

  • hello Anthony,

    thanks for your response,

    I tried but that doesn't work,

    I have write this for circumvent the problem:

    ----------------------------------------

    bin_declaration.h

    ----------------------------------------

    #define b00000000     0x00

    #define b00000001     0x01

    #define b00000010     0x02

    ...

    #define b11111111     0xFF

    ----------------------------------------

    ----------------------------------------

    main.c

    ----------------------------------------

    #include bin_declaration.h

    uint8_t toto = b00000001;

    ----------------------------------------

    that works but is it possible to declare direcly a constant in binnary format ?

    this solution is good for 8 bit format but will take a lot of time for 16 bit or 32 bits format.

    Regrads,

    Vincent.

  • Sorry, but C does not support binary constants. In C constants are either octal, decimal or hexadecimal.

  • Thanks Frank,

    I came back with the second part of my original question:

    "

    I see in the same way that in the exemple program renesas never use :

    unsigned  char or unsigned int but uint8_t, is it explain in a documentation ?  All of this type redefinition are their listed in a documentation or in  header  ".h" or ".c" file?

    I use the pdg library with the RSKRX210 and I can't find where this type definition are write.

    Regards,

    Vincent.

  • As FrankL says, C does not support binary constants. HEW does support them as a non-standard C extension, but you do need the 0 in front of the b. In other words b10100110 doesn't work but 0b1010110 does.

    It is considered poor practice to use raw integer types in C because they are impementation dependant, and therefore non portable. That is why MISRA flags raw types up as a violation. Using uint8_t and its friends (by #include ) makes your code portable.