This is a newbie question regarding Bitwise Operators in C:

The variable original is initialized to 0xABC.

unsigned int original = 0xABC;

I know that 0xA = 10 in HEX
but what does 0xABC mean? Testing it in the compiler I get the following value "2748". But how does this value came to be?

Hey its quite easy , 0x is hex right then ABC is calculated as follows :
A * 16^2 + B * 16^1 + C * 16^0 i,e
10 * 484 + 11 * 16 + 12 * 1
2748

Hey its quite easy , 0x is hex right then ABC is calculated as follows :
A * 16^2 + B * 16^1 + C * 16^0 i,e
10 * 484 + 11 * 16 + 12 * 1
2748

I took a course of Logic at my college, I can't believe I missed this... :icon_eek:
Anyway, thanks 4 the help ! SOLVED!

Here is a guide to convert decimal to binary in detail.Try this.
Apply the same theory for octal (use 8 to divide decimal numbers) and hexadecimal (use 16).Or

Once you have binary number say 10011011 its really easy to convert it into any form.
Say octal pair three digits from right to left
(when short of digits use 0's):
010 011 011
2 3 3

Say hex pair four digits right to left :
(when short of digits use 0's)
1001 1011
9 B

^^^ 16^2 is not 484. (!!)

^ the method to convert binary will only work on bases with a power of 2... Works for octal, hex, and base-64 (armored ascii)... won't work for decimal.

but other than the details, your methods are correct. :)


.

commented: Good catch buddy !!! Slip of keys .... ;) +1

Ya sorry miss typing : ;)

Here is the errata

A * 16^2 + B * 16^1 + C * 16^0 i,e
10 * 256 + 11 * 16 + 12 * 1
2748

Ya pairing system works only on powers of two where pairs of x digits are made to find value in base n system when binary is given where 2^x=n.

Every thing else is correct !!! :)

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.