math hex dec
math hex dec
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
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
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: math hex dec
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
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
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
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
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: math hex dec
Does this make any sense to anyone?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: math hex dec
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
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: math hex dec
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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: math hex dec
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.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: math hex dec
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.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: math hex dec
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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]