PDA

View Full Version : How To: Interchange hex and dec-manually


BrainWave
July 11th, 2008, 08:14 PM
There's no thread to teach you how to do that yet, so......
Oh, I've figured them out myself.

First, remember at least 15 values of hex numbers. They a shown below:

Hex---Dec
1------1
2------2
3------3
4------4
5------5
6------6
7------7
8------8
9------9
A------10
B------11
C------12
D------13
E------14
F------15
10----16

And the list goes on......

Now, for conversions
Normally when you use a hex tools, you'd find all the hex values to be shown in pairs.
Before any conversions, let a hex value be "xy"

Dec--->Hex
All you have to do is to multiply the x value by 16, then add y.
For example, for AA, the x value is A (which is 10) and the y value is A (which is also 10)
The dec. value=10(16)+10=170

(p.s, can anyone use a hex-dec calculator or something to check whether it's correct?)

Hex--->Dec
It's pretty much straight forward. All you have to do is the divide the dec. value by 16. The quotient(sp?) is the x value and the remainder is the y value.

KhaosKnight
July 12th, 2008, 12:49 PM
you could just you the calculator on your computer...change to scientific view then type your number, then click on the Hex box and it converts your number and vice-versa

thethethethe
July 12th, 2008, 07:22 PM
khaosknight1, that's a stupid post. It says manually. Not via computer ways. At least that's what I think this thread is for.
I already know how to do this, but it's good that it'll appear here.
Do you know how to go from Binary->Decimal? I can go from Decimal to binary, but I'm wondering how to do the reverse.

Thrace
July 13th, 2008, 01:58 AM
khaosknight1, that's a stupid post. It says manually. Not via computer ways. At least that's what I think this thread is for.
I already know how to do this, but it's good that it'll appear here.
Do you know how to go from Binary->Decimal? I can go from Decimal to binary, but I'm wondering how to do the reverse.
Isn't it like this:
10110 = 1*2^5 + 0*2^4 + 1*2^3 + 1*2^2 + 1*2^1 + 0*2^0
I'm pretty sure that's right.

I'm not sure how useful this thread is going to be for most people. Unless you can do it immediately in your head I can't really think of a reason why you wouldn't simply use a converter. However this thread might be quite good for the newer hackers who don't even know what hex is.

score_under
July 13th, 2008, 06:18 AM
khaosknight1, that's a stupid post. It says manually. Not via computer ways. At least that's what I think this thread is for.
I already know how to do this, but it's good that it'll appear here.
Do you know how to go from Binary->Decimal? I can go from Decimal to binary, but I'm wondering how to do the reverse.
Bin -> Dec:

Eg. 1001001
1. Take first DIGIT from the sequence (now we have 001001 and 1)
2. If there are any DIGITs left in the first NUMBER, double the second NUMBER (now we have 001001 and 2), otherwise stop.
3. Take the new first DIGIT in the first NUMBER, and add it to the second NUMBER (now we have 01001 and still 2).
4. Repeat 2 and 3 until you run out of DIGITs in the first NUMBER.

So 1001001
1. 001001 & 1
2. 001001 & 2
3. 01001 & 2
2. 01001 & 4
3. 1001 & 4
2. 1001 & 8
3. 001 & 9
2. 001 & 18
3. 01 & 18
2. 01 & 36
3. 1 & 36
2. 1 & 72
3. 73
So 73 is your answer.

To convert back from Dec to Bin...
e.g. 45
1. If the first NUMBER is odd, take 1 from it and add the digit "1" to the 2nd NUMBER, else add the DIGIT "0" to the 2nd NUMBER. (now we have 44 and 1)
2. If the first NUMBER is not 0, half the first NUMBER. (now we have 22 and 1)
3. If the first NUMBER is odd, take 1 from it and add the DIGIT "1" to the start of the 2nd NUMBER, else add the DIGIT "0" to the start of the 2nd NUMBER. (now we have 22 and 01)
4. Repeat 2 and 3 until you run out of DIGITs in the first NUMBER.

45
1. 44 & 1
2. 22 & 1
3. 22 & 01
2. 11 & 01 As you can see, I take 1 off this 11 in the next one...
3. 10 & 101 ... and add it to the start of the binary.
2. 5 & 101 Same with this one
3. 4 & 1101
2. 2 & 1101 ...But not this one, as it's even.
3. 2 & 01101
2. 1 & 01101
3. 0 & 101101


If this is hard to follow, I'm sorry!

Also, quick byte-to-hex conversion in x86 asm (because it's slightly related):
assume AL = byte to convert, and [ebp-4] contains the pointer to the string

.intel_syntax noprefix
mov bl,al
and al,0Fh
cmp al,0Ah
sbb al,69h
das
xchg al,bl
shr al,4
cmp al,0Ah
sbb al,69h
das
mov bh,al
xchg bl,bh
mov eax,[ebp-4]
mov [eax],bx
mov byte[eax+2],0

KhaosKnight
July 15th, 2008, 02:09 PM
khaosknight1, that's a stupid post. It says manually. Not via computer ways. At least that's what I think this thread is for.
I already know how to do this, but it's good that it'll appear here.
Do you know how to go from Binary->Decimal? I can go from Decimal to binary, but I'm wondering how to do the reverse.


Oh sorry i thought this was just a thread to teach people to convert Hex and Dec, i didnt mean it the way it came out, my apologies to TC