I was trying to understand how BITWISE OR works in C, and while looking on the web I found an explanation on msdn

But there I found this

short i = 0xAB00;

And I really don't know what this code does. I saw it for the first time and it would be really appreciated if anybody could help me explain what this does.

Thanks in Advance

Edited by romiaujla

4 Years
Discussion Span
Last Post by nmaillet

short is a smaller integer type than int (conceptually, at least). The 0xAB00 part is a hexadecimal literal value with the bit pattern 1010101100000000. It's just another way of writing the decimal value 43776 that makes the bit pattern a little easier to see, assuming you're familiar with hexadecimal. ;)

This would be roughly equivalent, and technically more correct because short is generally viewed as a 16-bit quantity where the signed positive limit is 32767:

int i = 43776;

Even more correct would be this:

long i = 43776;

The reason being that even int isn't required to be more than 16 bits, but long is required to be at least 32 bits.


Any numeric literal preceeded by 0x indicates a hexadecimal (or base-16) value. Basically each digit represents a value from 0-15 (0-9 then A-F). It is useful because two hexidecimal digits represent exactly one byte (00, 01, ... fe, ff in hexadecimal is equivalent to 0, 1, ..., 254, 255 in decimal), and makes things much easier to understand when dealing with bitwise operations (once you understand them).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.