Viewing Single values from Hex

Suppose I see - not in Xojo, but in documentation or in a file or similar - a hex value that is supposed to be floating point. For example I see written 42F00000. Obviously this is a 4-byte representation, in hex, of the floating point number.

Is there a quick way to find out what the decimal value of this is? Again, this is not a programming question, but is there a web site where you plug in the values and it shows the value? Or a little app that shows this? (I know I can write my own, and I did a long time ago, but I wanted to know how YOU did it.)

What system are you working on? If you’re on a Mac, you can use the pre-installed Calculator app and switch its display to “Programmer”. And it’s quite comfortable – you can even clickswitch the bit values in a binary number:

Couldn’t figure this out. Given the Calculator app, and if you saw the text “42F00000”, how would you get the decimal representation of those bytes?

Actually I figured something out, my question is a little misleading. 42F00000 isn’t really a hex number, it’s 4 bytes of hex smashed together. 0x42F00000 is always a Int32 number by definition, really, and historically AFAIK. But if you are interpreting those bytes as float, then what’s really needed is a Hex dumping app, which I use 0xED on Mac and HxD on Windows.

0xED allows you to highlight (in this case 4) byte values and it shows how they are interpreted in various ways in the display below. And that’s my answer. I didn’t think of this right away because I was on Windows when the question arose and HxD doesn’t have this feature.

HxD (Windows) is real nice because it can be used in context menus for any file (thank you!) and has a nice file-comparison feature. But it’s not Mac. 0xED (for Mac) doesn’t have either of these =( but the value-interpretation is real nice.

Why shouldn’t it be a hex number? But anyway, conversion is very easy in calculator: You click on the 16 in the segmented control on the upper right and enter the number as hex value via keyboard, the calculator buttons or from the clipboard. When you click on the “10” in the control, its decimal value is presented, and on 8 … you name it!

Calculator will interpret it as if its an integer
if you need some other interpretation (string, float etc) it doesn’t do that

Oh, you’re right! Hadn’t seen that (never tried it but I had seen I can still select the number of decimal places – which aren’t there …)

Perhaps Norman can shed any historical sense, but I believe it’s just pragmatic that when you see a hexadecimal number past two digits, you think AT LEAST integer and not a real number, and most often signed. If people had to denote how you were interpreting it, it would waste a lot of bandwidth/ink/time.

My fault for not being clear in the beginning.

To add a detail, the way I do Hex-Integer calculations on Mac is using an applet called PCCalc3. I hit F12 and it comes up and it has a Dec/Hex switch, and I just toggle it. I find this easier than starting the Calculator app. On Windows the included Calculator has this on the programmer mode. (But of course this isn’t square with float or double interpretations.)

[quote=179176:@Garth Hjelte]Perhaps Norman can shed any historical sense, but I believe it’s just pragmatic that when you see a hexadecimal number past two digits, you think AT LEAST integer and not a real number, and most often signed. If people had to denote how you were interpreting it, it would waste a lot of bandwidth/ink/time.
[/quote]
Can’t say why this is
But it’s definitely not uncommon to assume that 0x00000000 style is a “signed 32 bit value” when reality is it should be “some bunch of 4 bytes” - it could be 4 bytes from a string, 2 16 bit values one after the other, an unsigned 32 bit value or darn near anything else.

It’s just bytes

In Xojo, you can use a memoryblock to do the conversion.

  dim mb as new MemoryBlock(4)
  mb.Int32Value(0) = &h42F00000
  dim s as single = mb.SingleValue(0)
  MsgBox str(s)

yields “120”