I was trying to understand how BITWISE OR works in C, and while looking on the web I found an explanation on msdn
http://msdn.microsoft.com/en-us/library/17zwb64t.aspx

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
Raman

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.