hi, I was wondering if anyone knew of a good tutorial on hexadecimal and how it applies to ASM code? I want to start learning assembly but someone told me I need to learn this first.
Posted on 2002-01-03 17:30:44 by nub
If you're comfortable with binary, then you can consider hexadecimal to be a shorthand notation for binary. Every four bits can be encoded as a single hexadecimal digit. Every hexadecimal digit can be decoded as exactly four bits.
Posted on 2002-01-03 20:09:30 by tank
Hexadecimal (hex) is a base 16 numbering system (16 digits). This system is consisted of the following 16 symbols 0123456789ABCDEF in that order.

Symbols 0-9 equal to 0-9 base ten.
A = 10, B=11, C=12, D=13, E=14, F=15

Now what about 2 or more digits?
In decimal (base 10), 23 would be equal to 2*10 + 3*1 (10 & 1 being powers of ten)

Hex works the same, but you multiply by powers of 16:
0x23 = 0x2 * 0x10 + 0x3 * 0x1
Noting that 0x10 = 16 decimal:
0x23 = 2 * 16 + 3 * 1 = 35 decimal.
35= 0x3 * 0xA + 0x5 * 0x1 = 0x23
Binary uses powers of 2.

The remaiders of repeated division can be used to retrieve the digits in reverse order (1's place first).
Posted on 2002-01-03 20:20:24 by eet_1024
How hex relates to ASM....
It used to, a lot! Now though the world barely has any real men left.... :grin:
It is more important to understand binary for the purpose of anding, oring etc. than it is to know hex.
Hex just makes stuff easy, as it is grouping 4 bits together to form a single hexidecimal digit.

0000 -> 0x0
0001 -> 0x1
0010 -> 0x2
0011 -> 0x3
0100 -> 0x4
0101 -> 0x5
0110 -> 0x6
0111 -> 0x7
1000 -> 0x8
1001 -> 0x9
1010 -> 0xA
1011 -> 0xB
1100 -> 0xC
1101 -> 0xD
1110 -> 0xE
1111 -> 0xF

So 0xFF is 11111111 in binary (much easier to write, I can easily see two characters, but 7, 8, and 9 consecutive 1s start to look the same late at night)!

The way to count in Hex is the same as any other base, its just that we never learned how counting works!
In decimal or base 10 this is what happens:
We are working in base 10, so there are 10 symbols (0 -> 9).
Each digit represents 10^(position - 1) so the first position represents the number of 10^0 (1) in our number, and the third digit represents the number of 10^2 (100) in our number....
987 = (9 * 10^2) + (8 * 10^1) + (7 * 10^0)
It even holds true for numbers before the decimal point (10^(-1) = 0.1).

The same is true for binary, except you are working in base 2 this time.
So there are only 2 symbols used (0 -> 1).
First digit represents 2^0 -> 1s
Second digit represents 2^1 -> 2s
Third digit represents 2^2 -> 4s
And so on.

Also true for hexidecimal (base 16):
16 symbols (0 -> F (10 normal digits, plus 5 letters)).
First digit = 16^0 -> 1s
Second = 16^1 -> 16s
Third = 16^2 -> 256s

It works for any base there is (as long as you use integers, I've never really tried getting my head around base 1.25 because a quarter of a symbol is very difficult to write)....

If you don't know/understand anding etc. or this description post again, and I'll try to explain again (I'm a very bad teacher at the best of times)!

Mirno
Posted on 2002-01-03 21:25:50 by Mirno
Mirno:
Ever heard of base 2.54?
Posted on 2002-01-03 22:07:40 by eet_1024
Guys, im sorry, I think I asked about the wrong thing. This is an example of what I don't understand.. I thought is was hexadecimal.

I understand that 10h = 16, but what about a number like 202020h? why are all the extra 0's needed?

a couple examples of what im talking about are (in iczelion's tuts):

and eax,0ffffh
mov cf.crTextColor,0FF0000h
Posted on 2002-01-03 22:24:49 by nub
It's like asking:

mov eax, 10000

Why are all the extra zeros needed? :grin:

The zeros determine the power of the digit.

1h = 1
10h = 16
100h = 256
1000h = 4096

Also a hex number must start with a digit in MASM. If it didn't then MASM wouldn't know if it was a number or a label / macro / equate.

mov eax,ffffh ; this doesn't work unless ffffh is defined.
mov eax,0ffffh ; this works

mov eax,0ff0000h ; this is a big number 255*256*256
Posted on 2002-01-03 22:28:01 by bitRAKE
nub, you might want to play around with the windows calculator,
calc.exe . Switch it to scientific mode, and you can play around in
binary, decimall, octal, and hex. And perform shift operations as well.
Posted on 2002-01-03 23:50:25 by f0dder