LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C << / (https://www.linuxquestions.org/questions/programming-9/c-353389/)

ewt3y 08-15-2005 05:56 AM

C << /
 
#define COMPAT_VERSION_MAJOR 3
#define COMPAT_VERSION_MINOR 2
#define COMPAT_VERSION ((COMPAT_VERSION_MINOR << 8) \
| COMPAT_VERSION_MAJOR)


Plz explain what << 8 and \ mean ?

Hko 08-15-2005 06:15 AM

Re: C << /
 
Quote:

Originally posted by ewt3y
#define COMPAT_VERSION ((COMPAT_VERSION_MINOR << 8) \
| COMPAT_VERSION_MAJOR)

Plz explain what << 8 and \ mean ?
"<<" is one of C's bitwise operators. They are used to fiddle with the actual bits (ones and zeroes).
"x << 8" means: "take x, and shift its bits 8 bit-positions to the left. (8 bits == 1 byte). So "x << 8" is equivalent to multiplying by 256. Likewise "6 << 1" evaluates to 12 (the bits of 6 == 00000110 are shifted one bit-position to the left: 00001100, which is 12).

Example:
Say x == 254(decinal) == FE(hexadecimal) == 11111110(bin).
Then (x << 8) will be: 1111111000000000(bin) == FE00(hex) == 65024(dec).

Th \ just "escapes" the newline following it, so the compiler will consider the two lines as one. Example:

printf("hello \
there");

will be processed by the compiler as if it were:

printf("hello there");


All times are GMT -5. The time now is 06:25 PM.