Author |
Message |
Cataract2
| Posted on Thursday, August 23, 2012 - 10:35 am: |
|
I'm working out a problem and can not figure out how to do this. I know it's simple, but I need help. I'm trying to convert decimal to hexadecimal by hand. 1063.5 Anyone able to explain how to go about this? |
Jaimec
| Posted on Thursday, August 23, 2012 - 10:41 am: |
|
By hand? No, I'm afraid I've gotten far to used to doing it with a calculator (and the "Convert" built-in function). It would be a series of "Divide by 16s" though. |
Reindog
| Posted on Thursday, August 23, 2012 - 11:18 am: |
|
Convert the integer and remainder parts separately. 1063 (base 10) = 427 (base 16) 0.5 = 5/10 = 8/16 so the converted value is 427.8 hex. Notice that the digit immediately to the right of the decimal is the 1/16th place. |
Argentcorvid
| Posted on Thursday, August 23, 2012 - 11:21 am: |
|
it depends on how it's encoded which will depend on the device you're putting the number into. general-purpose computers mostly use IEEE double-precision Floating point. If you're putting the number into an embedded device (like say the ECM), there might not be space for that, and they might use fixed point numbers, or in some cases only support integers. |
Cataract2
| Posted on Thursday, August 23, 2012 - 11:38 am: |
|
Rein, I understand the base 16. I just don't know how you got the 427. I figured out how to work the .5 part to get 8 through dividing 1063.5/16 which for my 66.46875. Then I multiplied 46875 by 16 which for me 7.5. rounding up for my the 8. I just can't figure out how to get the 427. |
Sifo
| Posted on Thursday, August 23, 2012 - 11:39 am: |
|
Anyone else ever learn to do that with the tables on an IBM yellow card? Anyone else ever hear of an IBM yellow card? 427 is the correct answer BTW. |
Sifo
| Posted on Thursday, August 23, 2012 - 11:42 am: |
|
If you need the exact answer, it's 427.8 I'm far too lazy to work it our manually these days when computers can do it for you in a fraction of a second... http://www.mathsisfun.com/binary-decimal-hexadecim al-converter.html |
Danger_dave
| Posted on Thursday, August 23, 2012 - 11:52 am: |
|
Hexadecimal is not as simple as #000 and #FFF. Sometimes there are shades of #333. Enough to make you see #F00 sometimes. |
Reindog
| Posted on Thursday, August 23, 2012 - 11:53 am: |
|
Use the hex conversion button on your calculator. The easiest way is to convert an integer, N, into binary is successive divisions by 2 and retaining the remainder (0 or 1). This will yield the base 2 equivalent. For example, 1063 -> 10000100111. Conversion to hex from binary is trivial. Group each four-bits into hex. (0001->1,...,1001->9,...,1010->A, etc). 10000100111 -> 427 hex. |
Natexlh1000
| Posted on Thursday, August 23, 2012 - 12:00 pm: |
|
He's obviously doing this for school. Otherwise, there wouldn't be a fraction in there! So that's why he can't just type in CALC.EXE and set "view" to scientific and then covert it the cheaty-way. Calc.exe doesn't allow for hex fractions so that's probably a "gotcha" to see who is cheating. |
Court
| Posted on Thursday, August 23, 2012 - 12:05 pm: |
|
>>>0.5 = 5/10 = 8/16 so the converted value is That's pretty slick . .. can you convert me? |
Mr_grumpy
| Posted on Thursday, August 23, 2012 - 12:10 pm: |
|
What would you like to be converted to Court? Natural gas? Buddhism? Diesel? or 12 year old single malt. |
Jaimec
| Posted on Thursday, August 23, 2012 - 12:33 pm: |
|
In my field, it's not 427, it's 0427 (two bytes) Just sayin' |
Court
| Posted on Thursday, August 23, 2012 - 12:38 pm: |
|
quote:Natural gas? Buddhism?
Diesel? or 12 year old single malt.
I can narrow it to two . . . and suspect, given my prior experience with Rein, I'm left with only the 12 Year Old Single Malt. Besides . . . as much as I'd like to be converted to a Buddhist . . . I'm not sure I'd be able to find my way ohm. Beam me up . . . . |
Brijasher
| Posted on Thursday, August 23, 2012 - 12:39 pm: |
|
16^3 = 4096 16^2 = 0256 16^1 = 0016 16^0 = 0001 1063/(16^2) = 4 remainder 39 39/(16^1) = 2 remainder 7 7/(16^0) = 7 = 427 |
Kyrocket
| Posted on Thursday, August 23, 2012 - 12:41 pm: |
|
That's baaaad |
Brijasher
| Posted on Thursday, August 23, 2012 - 12:46 pm: |
|
And for completeness: 16^3 = 4096 16^2 = 0256 16^1 = 0016 16^0 = 0001 16^-1= 0.625 1063.5/(16^2) = 4 remainder 39.5 39.5/(16^1) = 2 remainder 7.5 7/(16^0) = 7 remainder 0.5 0.5 < (16^-1) so stop dividing here and convert the digits 4 => 4 2 => 2 7 => 7 0.5 => 0.8 = 427.8 |
Reindog
| Posted on Thursday, August 23, 2012 - 12:59 pm: |
|
In my field, 427 hex is 0x427 or 'h427, but I know you leading zero types. |
Brijasher
| Posted on Thursday, August 23, 2012 - 01:35 pm: |
|
You are absolutely correct, I missed the 6 steps required to properly add the leading '0x' =P For my penance, you get to present the steps to convert to proper IEEE double precision floating point.
|
Cataract2
| Posted on Thursday, August 23, 2012 - 01:44 pm: |
|
Brij, thanks for the explanation. Yes, I'm doing this for Digital Circuits. Starting my Electrical Engineering course. First day was yesterday and trying to get a jump. Frustrating myself instead. Brij, how did you get the remainder. When I run 1063.5/(16^2) through the calculator I get 4.154296875 |
Brijasher
| Posted on Thursday, August 23, 2012 - 01:54 pm: |
|
Yup, go back to elementary school when you had to do long division by hand. Take 4.15... and truncate it, then 1063.5 - (4 * 16^2) gives you 39.5 |
Reepicheep
| Posted on Thursday, August 23, 2012 - 01:58 pm: |
|
Reindog beat me to it. 0427 is octal. (You are flushing out all us embedded C programmers...) |
Brijasher
| Posted on Thursday, August 23, 2012 - 02:01 pm: |
|
Something that will speed this up is if you have a scientific calc that can give you the modulus. I.e. 1039.5/256 = 4.15... 1039.5 mod 256 = 39.5 39.5/16 = 2.nnn 39.5 mod 16 = 7.5 |
Brijasher
| Posted on Thursday, August 23, 2012 - 02:03 pm: |
|
Bah, I didn't say 0427 anywhere. Everyone's a critic. Yeesh. |
Cataract2
| Posted on Thursday, August 23, 2012 - 02:06 pm: |
|
Thanks Braij. Been a long time for me so I have some serious cobwebs to clear. |
Argentcorvid
| Posted on Thursday, August 23, 2012 - 02:06 pm: |
|
quote:In my field, it's not 427, it's 0427 (two bytes)
and on intel machines it's stored 0x27 0x04. |
Sifo
| Posted on Thursday, August 23, 2012 - 02:08 pm: |
|
Can I hate the math and still like the mathematician? |
Brijasher
| Posted on Thursday, August 23, 2012 - 02:14 pm: |
|
Uh oh, here comes the big-endian, little-endian fight. Hmmm, which side do I want to make fun of more? |
Brijasher
| Posted on Thursday, August 23, 2012 - 02:18 pm: |
|
And for all you programmers, here is a little something for you to run at your nearest command line. perl -e 'while 1{fork}' Let me know how it works out for you. |
Cataract2
| Posted on Thursday, August 23, 2012 - 02:27 pm: |
|
Hopefully I don't piss anyone off if I throw questions out from time to time regarding my classes. Sometimes a bigger pool helps with this stuff. |