# Mathematical conversion of hex to decimal

I am stuck with a very trivial coding issue. Please refer the link below: Cordic Algorithm using Verilog By what mathematical rule hex 26dd2b6a is equal to 0.607252935008814?

• My best guess is Single precision IEEE 754. Sep 17 at 0:00
• Some kind of scaling for the units being used. Maybe it represents a fraction of 2*pi? Sep 17 at 0:04

The number appears to be encoded as a fixed point similar to Q1.30 Q-format by Texas Instruments

If you take the 0x26dd3b6a and divide it by 0x40000000 you will get the expected value 0.6072529350

You may use Calculator in Windows, switch it to Programmer view, select HEX and paste your hex string. Then convert to decimal. You may need to copy to clipboard before switching to standard or scientific calculator mode where you can display real numbers (and divide by the decadic equivalent of 0x40000000).

Since all of your constants are positive it is hard to tell whether the intended format is signed or unsigned.

In other words (assuming unsigned) the two MSB bits are the integral part and the remaining 30 bits are the fractional part.

If the format is signed (as the Q1.30 would be) then the MSB is sign bit followed by the integral part and 30 bits of the fractional part. (Doesn't make any difference here for positive numbers < 2.0).

• Thank you @Martin. How to do this division?. I am really stuck in a debugging kind of issue. Sep 17 at 2:13
• Why you divide by 0x3fffffff, but not by 0x4fffffff. Please eloborate Sep 17 at 2:41
• @Deepika To answer the two questions: - Why to divide by 0x3fffffff? This is a binary number that has all 30 least significant bits set. This is equivalent to the highest value that can be expressed by your fractional portion. The correct answer is actually not 0x3fffffff nor 0x4ffffff but 0x400000. (Tiniest difference but still ;-)) - How to do the division? Convert your hex numbers to decadic and use calculator, right? 0x26DD3B6A/0x40000000=652032874/1073741824 = 0.607252935 Sep 17 at 3:16
• Hi @Martin Vana, suppose the number is 0x 5c33, then with what hex number should be divide. I really apolozise for asking so basic questions. Sep 17 at 4:30
• I think 0x5c33 be divided by 0x7FFF? Sep 17 at 4:45

h26DD3B6A is a straight binary fraction of 2^30

Converting to decimal, h26DD3B6A is d652,032,874
Converting 2^30 to decimal: d1,073,741,824

$$\{{652032874}\over{1073741824}} = 0.607252934\$$

I'd guess those two leading bits of the 32-bit number have something to do with signs.

Go ahead and try things like little or big endian 32-bit IEEE754 floats, or fractional signed numbers, seeing all these are < 1.

But honestly, in FPGAs your bitwidths are scaled by the operations that you apply, and these values might literally just have one proportionality factor specified elsewhere.