Page 1 of 1
math hex dec
Posted: Sat Apr 18, 2009 3:52 pm
by kmtdk
Hi
i have been thinking about the convertion beteween hex and dec, mostly from hex to dec.
i know that the normal way is to convert hex to bin and then to dec ( i dont know 100% how you do that)
but is there not any other solutions ( FPU, or another calculation way ???)
KMT dk
Re: math hex dec
Posted: Sat Apr 18, 2009 5:03 pm
by DeletedAccount
Hi,
Hex to bin :
Take each digit and convert to bin in groups of 4
eg 6A (hex) = 0110 1010 (bin)
bin to hex :
Take digits in groups of four and convert to hex
eg 1111 0101 (bin) = F5 (hex)
hex to dec :
Summation of For i = 0 to No digits-1 (i+1) th digit * 16^ i
eg FF (hex) = (15 )* 16^1 + ( 15) * 16 ^ 0 = 255(dec)
oct to bin :
similar to hex , but take in groups of 3
bin to oct :
similar to hex , but take in groups of 3
oct to dec :
Summation of For i = 0 to No digits-1 (i+1) th digit * 8^ i
55 (oct) = 5 * 8 ^ 1 + 5 * 8 ^ 0 = 45 (dec)
Hope you get the pattern
. However do your reading first , any text book can teach this
Regards
Shrek
Re: math hex dec
Posted: Sat Apr 18, 2009 5:11 pm
by kmtdk
hehe
eh ..
minor mistake from my side ( DOH )
im talking about convering from hex, using hex ( os code)
of cause i have my "own" way, but it is not too good with big numbers ( and is generaly slow)
KMT dk
Re: math hex dec
Posted: Sat Apr 18, 2009 5:35 pm
by Love4Boobies
Does this make any sense to anyone?
Re: math hex dec
Posted: Sat Apr 18, 2009 6:52 pm
by Troy Martin
I think what the OP is trying to do is this:
Code: Select all
; AX = 0xF00D
mov ax,0xF00D
call hex_to_dechex_word
; DX:AX (or EAX) = 0x61453 (decimal for 0xF00D encoded in hexadecimal
call print_hex_long ; prints out DX:AX or EAX on the screen
Re: math hex dec
Posted: Sat Apr 18, 2009 6:57 pm
by Love4Boobies
If that's the case (although I really doubt that's what he meant) he could probably use a little trick like converting to decimals and storing them as BCDs and then just reading the bytes from memory. My trick however only works for x86 and architectures that support BCDs.
Re: math hex dec
Posted: Sat Apr 18, 2009 11:45 pm
by Firestryke31
Any architecture that can store and operate on at least one half byte of data supports BCDs. It's just faster if it supports it in hardware.
Re: math hex dec
Posted: Sun Apr 19, 2009 11:22 am
by Troy Martin
Any architecture that supports operations on a single byte of data and can bitwise shift a single byte of data around supports BCDs. Having a stack helps too.
Re: math hex dec
Posted: Sun Apr 19, 2009 1:42 pm
by Love4Boobies
Well sure. Any system supporting a keyboard and a little monkey that does additions can add numbers. It's still not a good idea to do it that way. x86 has special BCD instructions.