I was wondering if anyone here could give me a good site that teaches me hexadecimal that I often see in code.
I looked on the FAQ board and that didn't have anything so I hope I didn't miss a post here that had it.
Printable View
I was wondering if anyone here could give me a good site that teaches me hexadecimal that I often see in code.
I looked on the FAQ board and that didn't have anything so I hope I didn't miss a post here that had it.
There's not much to teach about hexadecimal. It basically has 16 characters, 0 to F. Good links can be made between hex and binary, for example:
1d=1h (1 decimal = 1 hex)
2d=2h
4d=4h
8d=8h
16d=10h
32d=20h
64d=40h (64 decimal = 40 hex)
128d=80h
As you can see, the binary series translates well into hex. For that reason, people often use hex to represent things that are related to binary.
What exactly do you want to know about hexadecimal? If you just want to convert from one system to the other, use calc.exe.
Decimal Hex
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 b (yes theres a reason why its not caps)
12 C
13 d
14 E
15 F
16 10
17 11
18 12
It keeps going on from there. Basically you just have to know that each "power of" is to 16 instead of 10, just as binary is a power of 2 for each place. As for the reason why its not in caps, it usually doesn't matter in programming but in electronics in 7 segment LCD displays you can only display b and d in lowercase otherwise they would look like 8 and 0.
EDIT:: I'M GOING BLIND!
He did explain, axon.
decimal = base ten:
So hex is base 16 therefore there are 16 numerals: 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,fCode:1 = 10^0
2 = 10^0*2
...
10 = 10^1
20 = 10^1*2
21 = 10^1*2 + 10^0
...
And each digit represents a power of 16:
The same goes for binary. Base 2, so only two numerals (0,1) and each digit is a power of two...so 1101 is 13 (2^0 + 2^2 + 2^3)Code:1 = 16^0 (1 in decimal)
...
10 = 16^1 (16 in decimal)
...
[code]0xbd0e8406, 0xfb56, 0x4322, 0x8b, 0xc6, 0xbd, 0x6e, 0x48, 0x1f, 0x55, 0x64[code]
In that example what does the 0x mean?
Is that to identify it is using hex now or what?
>>Is that to identify it is using hex now
Yes.
As bennyandthejets said, Hex is used as an alternative to binary. Everything inside the compurer is done and stored in binary.
Hex is most-often used when the number is being used as a bit-pattern rather than "just a number." So, you would generally be using bitwise operations with hex... It is rare to use addition & subtraction, etc. It is also quite common to use hex for addresses. ...So, you might use addition and subtraction with hex addresses.
There are two reasons for avoiding the direct use of binary - When you get beyond one byte (8-bits), binary gets difficult to read... you have to start counting bits. And, it's not easy to use binary directly in C / C++... You can't use binary in your source code.
The reason that hex is used in place of decimal, is that it is much easier to convert between binary and hex than between binary and decimal. If you learn 14 conversions (you already know zero and one), you can convert numbers of any size in your head!
The built-in Windows calculator can convert between hex/decimal/octal/binary.
Start->Programs->Accessories->Calculator->Scientific->Hex.
The 0x notation is to tell the C / C++ compiler that the number is hex. Different computer languages use different notation.
Good try on the code tags... you forgot the slash in the closing tag [/code]. :)
Thank you all, I now understand hexidecimal.