MHB Converting Decimal to Hexadecimal for Compass Corrections

  • Thread starter Thread starter Dbugger2020
  • Start date Start date
AI Thread Summary
The discussion focuses on the challenges of converting decimal values to hexadecimal for compass corrections in a program rewrite. The user encounters inconsistent hexadecimal outputs for the same decimal input when calculating corrections A, B, and C, suggesting a systematic issue with the conversion method. They detail their approach of converting decimal to binary first and then to hexadecimal, highlighting the process of determining binary fractions for the decimal part. The user arrives at a repeating binary fraction and translates it into hexadecimal, ultimately concluding that 1.78 in decimal equates to 1.C6318C6318C6318... in hexadecimal. Assistance is sought to resolve the discrepancies in the conversion results.
Dbugger2020
Messages
1
Reaction score
0
I am re-writing a program that calculates compass corrections and I seemingly cannot get the conversions from Decimal to Hexidecimal correct.

The original program is written in quick basic (but i of course cannot locate the bas (source) file.
For the first correction, let's call it "A". if I enter 1.78 as my decimal, the hex return is 00 05 10. but, if i enter 1.78 as the decimal for "B", i get, 10 00 FE. For "C", i get, 20 00 FE

So obviously, the leading bits of the return (00,10,20) are the place holders for each correction 00 being A, 10 being B, and 20 being C.

Any conversion method I've tried after that place holder yields incorrect results or at least results that do not correspond.

Any help is most definitely appreciated
 
Mathematics news on Phys.org
I would convert to binary first, then to base 16. Since 16 is 2 to the fourth power that second conversion is easy. First 10^0, 16^0, and 2^0 are all one so the integer part of 1.78 is still 1. 0.78= 0.5+ 0.28 so the first bit after the "decimal" point is 1. 0.28= 0.25+ 0.03 so the next bit is also 1.

So far we have 1.11 (base 2) which is 1.75 (base 10). 1/8= 0.125, 1/16= 0.0625, and 1/32= 0.03125 are all larger than 0.03 so the next three bits are 0. 1/64= 0.015625 is less than 0.03 so the next bit is 1. So far we have 1.110001 (base 2) which is 1.765625 (base 10). 0.03- 0.015625= 0.014375. 1/128= 0.00390625 which is smaller so the next bit is 1. 0.014375- 0.00390625= 0.00246875. 1/256= 0.001953125 which is smaller so the next bit is 1. 0.00246875- 0.001953125= 0.000515625. 1/512= 0.001953125 which is larger so the next bit is 0. I think that is sufficient to recognize that the "repetition" (which has to happen since 1.78 is a rational number) is 1.1100011000...= 1.1100 0110 0011 0001 1000 1100...

I wrote it in 4 bit groups because 16= 2^4 so we can directly convert each group into a hexadecimal "digit". 1100= 2^3+ 2^2= 8+ 4= 12= C (hexadecimal), 0110= 4+ 2= 6. 0011= 2+ 1= 3. 0001= 1, and 1000= 8. In 1.78 (decimal) is 1.C6318C6318C6318... (hexadecimal).
 
Last edited by a moderator:
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Is it possible to arrange six pencils such that each one touches the other five? If so, how? This is an adaption of a Martin Gardner puzzle only I changed it from cigarettes to pencils and left out the clues because PF folks don’t need clues. From the book “My Best Mathematical and Logic Puzzles”. Dover, 1994.
Back
Top