28 April, 2011

Representing binary in C code

Hi all

    It has been a long time... :)

    Hey does any one know if it is possible to add prefix before a number to represent binary

    For example
        unsigned char a = 0xF0;    This is for hexadecimal
       
Is there a similar representation for binary and octal?
I already tried

    unsigned char a = 0b11110000;

It is possible in MPLAB but not with gcc on linux.
Any solutions...???



3 comments:

  1. Sorry my mistake it works on linux with gcc too... :)

    But what about octal....???
    Does any one know??

    ReplyDelete
  2. Yes it is possible ... We have to just give one 0 before the octal number which we are assigning.

    For example:

    #include

    int main(void){
    unsigned char a = 0171;
    printf("%c\n", a);
    printf("%d\n", a);
    return 0;
    }

    The output of this program is
    y
    121

    y represents the character value of 121, which is decimal value of octal 171.

    ReplyDelete
  3. Good man thanks...
    This is what happens if u don't code for long time... :(

    ReplyDelete