Go Back   The PokéCommunity Forums > ROM Hacking > Research & Development
Reload this Page How To: Interchange hex and dec-manually

Notices
For all updates, view the main page.

Research & Development Got a well-founded knack with ROM hacking? Love reverse-engineering the Pokémon games? Or perhaps you love your assembly language. This is the spot for polling and gathering your ideas, and then implementing them! Share your hypothesis, get ideas from others, and collaborate to create!
Research & Development programs in this forum are subject to moderator approval before they are displayed.



Reply
 
Thread Tools
  #1    
Old July 11th, 2008 (08:14 PM). Edited August 29th, 2008 by BrainWave.
BrainWave's Avatar
BrainWave BrainWave is offline
A new idea sprouts
Team Sinnoh
 
Join Date: Jun 2005
Location: Home
Age: 23
Gender:
Nature: Careful
Posts: 156
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.
Reply With Quote
  #2    
Old July 12th, 2008 (12:49 PM).
KhaosKnight's Avatar
KhaosKnight KhaosKnight is offline
The 1 and only Khaotic Hacker
Team Kalos
 
Join Date: Dec 2007
Nature: Relaxed
Posts: 355
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
__________________





Reply With Quote
  #3    
Old July 12th, 2008 (07:22 PM).
thethethethe thethethethe is offline
Team Johto
 
Join Date: Jun 2007
Location: Melbourne, Australia
Gender: Male
Posts: 1,104
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.
__________________
Gone.
Reply With Quote
  #4    
Old July 13th, 2008 (01:58 AM).
Thrace's Avatar
Thrace Thrace is offline
@tion
Team Hoenn
Gold Tier
 
Join Date: Jun 2007
Age: 24
Gender: Male
Posts: 1,048
Quote originally posted by thethethethe:
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:
Code:
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.
__________________
Reply With Quote
  #5    
Old July 13th, 2008 (06:18 AM). Edited July 13th, 2008 by score_under.
score_under's Avatar
score_under score_under is offline
I program the *other* ASM.
Team Kanto
Crystal Tier
 
Join Date: Aug 2005
Location: Hertfordshire, England
Age: 22
Nature: Rash
Posts: 525
Quote originally posted by thethethethe:
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!
Spoiler:

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
Code:
.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
__________________
Plz not to PM me, I don't come here often enough. Email if you need me
Reply With Quote
  #6    
Old July 15th, 2008 (02:09 PM).
KhaosKnight's Avatar
KhaosKnight KhaosKnight is offline
The 1 and only Khaotic Hacker
Team Kalos
 
Join Date: Dec 2007
Nature: Relaxed
Posts: 355
Quote originally posted by thethethethe:
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
__________________





Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are UTC -8. The time now is 12:53 PM.