Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

HEX Numbers

JohnNichols
Honored Contributor I
35 Views

My education is clearly sorely lacking in terms of real numbers in Hex or Binary Format.

I have a binary file that I can nicely read with Hex Editor.  I found after a few weeks of using the program it has a button to turn the hex code in real4 numbers as shown.  The first column is just small count column, the second column is the barometric pressure, the third is random garbage and the fourth is some counter. Each line is one second apart in real time. 

Screenshot 2026-05-07 071134.png

I understand how the 7c307c44 can be translated to a large decimal, but how in Fortran do I get the real number that is within the Hex code.   The JSON file for this dat file says they are floats, which I assume is C standard.  

 

Screenshot 2026-05-07 082850.png

 

0 Kudos
1 Reply
Arjen_Markus
Honored Contributor II
31 Views

That is easy enough:

  • Open the file as "acess = 'stream' - this defaults to unformatted reading
  • Then in a loop, read one real at a time
  • Print the real

If you want some code (not tested, so caveat emptor for typos):

integer :: i
real :: x
open( 10, file = 'mydata', access = 'stream' )
do i = 1,20
    read( 10 ) x
    write(*,*) x
enddo

If you get sensible numbers, then you know you are on the right track. Looking at the screenshots, I'd say, this should do it.

Of course, I have no idea what the internal organisation of the file is (grouping of the data in records or the like).

Reply