• C

hi experts,

I came across several programs that has a declaration in hex for example 0x000 whis I believe will be for bits manipulator and I really do not know what it means actually. I just wonder if there is any site can explain the reason they use such declaration and the purpose for doing so...

Basically, is there any reference I can  refer to when I come across this type of declarion again...

TQ
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Just about any C/C++ book will show the different ways you can create literals of the language.  In this case, a literal hexidecimal number is created by prepending the 0x.

Hexadecimal numbers are base 16 numbers, just like binary numbers are base 2 numbers.  A hexidecimal digit can be 0-9,A,B,C,D,E,F.  Where A=10, B=11, C=12, D=13, E=14, and F=15.

For instance hexadecimal A which equals 10 in decimal is also equivalent to 1010 in binary.

In both C and C++, you can create decimal, octal, or hexidecimal numbers.  A decimal number such as 10, requires no prefix.  A hexadecimal number such as A, requires the 0x prefix.

Examine this code:
int i = 10;   // i gets the decimal value of 10
int i = 0xA; // i also gets the decimal value of 10

People often use hexadecimal notation as a condensed form of reading binary.  Since an A in binary is 1010, it is much easier just to read a single character, instead of 4.

See the following websites:
http://www.novo-assoc.com/PLUGPLAY/chapter4/33.HTM
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Hi tdubroffs,

What does the 0x means  then ?
0
Commented:
0x are the leading chars to tell then the number following is hexadecimal.
0
Author Commented:
hi tdubroff,
Thanks for response
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.