How to convert a specified byte in a binary file into a floating point number?For example, convert the 04-07 bytes in the first row of the figure into floating-point numbers, thank you experts!

The correct result is: 1006.27
The binary file is as follows:
598A0F0548917B44F6C87B44855B7B44D7637B44DA57BE45140B000000000000
ScriptingWindows回复: 怎样将二进制文件中的指定字节转化为浮点数字?excel VBA

Reply: How to convert the specified bytes in the binary file into floating-point numbers?This function cannot be implemented
CopyMemory v, b(0), 4
Re: 怎样将二进制文件中的指定字节转化为浮点数字?
filename = Save Text File(
"$temp/deleteme.bin",
Hex To Blob( "598A0F0548917B44F6C87B44855B7B44D7637B44DA57BE45140B000000000000" )
);
// load the entire file. You could use the blob() parameter
// to load a smaller part of the file by offset and length.
blobdata = Load Text File( filename, blob() );
// convert the binary data to a matrix. The 4 means 4 byte chunks
// and "little" means the least significant byte comes first (little endian.)
numbers = Blob To Matrix( blobdata, "float", 4, "little" );
// print the values; JMP uses 8-byte floating point and will
// display more resolution than is actually available.
For( i = 1, i <= N Rows( numbers ), i += 1,
Write( "\!n", i, " ", numbers[i] )
);
1 6.74923813801151e-36
2 1006.27001953125
3 1007.14001464844
4 1005.42999267578
5 1005.55999755859
6 6090.9814453125
7 3.97408244482518e-42
8 0
There is a similar function, Matrix To Blob, for converting the other direction.
4-byte floats have 6 or 7 significant digits. 8-byte floats have 15 or 16 significant digits.
https://en.wikipedia.org/wiki/Single-precision_floating-point_format
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
If you try to use the windows hex calculator, which has a convenient bits display, be sure to reverse the bytes.
48917B44 -> 447B9148 -> 0 10001000 11110111001000101001000 -> 2^(136-127) * (1+1/2+1/4+1/8+1/16+0/32+1/64 +...)
Re: How to convert the specified bytes in the binary file into floating-point numbers?Thanks experts!
In this binary file
00, 01 bytes-year, month and day
02, 03 bytes-time division

Do you want to increase the segmentation in the code? Thanks again!
numbers = Blob To Matrix( blobdata, "float", 4, "little" );
Re: How to convert the specified bytes in the binary file into floating-point numbers?I still have the ability to perform this operation.
I uploaded the entire file, it has 5070 lines of data like this.
See how to encode?
thanks!
00 to 01 bytes: indicates the date. If the value is num, the date calculation method is as follows:
year=floor(num/2048)+2004;
month=floor(mod(num,2048)/100);
day=mod(mod(num,2048),100);
02 to 03 bytes: indicates the number of minutes from 0 o 'clock to the present
04 to 07 bytes: float
08 to 11 bytes: float
12 to 15 bytes: float
16 to 19 bytes: float
20 to 23 bytes: float
24 to 27 bytes: integer
28 to 31 bytes :(reserved)
Re: 怎样将二进制文件中的指定字节转化为浮点数字?You could make a graph of the data like this. It looks like there are some outliers!
data extracted from the zip file and graphed to see outliers.data extracted from the zip file and graphed to see outliers.
/*
00 to 01 bytes: indicates the date. If the value is num, the date calculation method is as follows:
year=floor(num/2048)+2004;
month=floor(mod(num,2048)/100);
day=mod(mod(num,2048),100);
02 to 03 bytes: indicates the number of minutes from 0 o 'clock to the present
04 to 07 bytes: float
08 to 11 bytes: float
12 to 15 bytes: float
16 to 19 bytes: float
20 to 23 bytes: float
24 to 27 bytes: integer
28 to 31 bytes :(reserved)
*/
za = Open( "z:/445.zip", "zip" ); // open the zip file
datasetname = (za << dir)[1];
blobdata = za << read( datasetname, Format( blob ) ); // load the member as a blob
//
// the following 3 lines import ALL of the data each time. Later,
// only use the columns that were really in that format.
//
integer2 = Blob To Matrix( blobdata, "uint", 2, "little", 16 ); // get the 2-byte unsigned ints for columns 0-1 and 2-3
integer4 = Blob To Matrix( blobdata, "uint", 4, "little", 8 ); // get the 4-byte unsigned ints for columns 24-27 and 28-31
float4 = Blob To Matrix( blobdata, "float", 4, "little", 8 ); // get the 4-byte floats for columns 4-23
// pre-process the matrix columns; no explicit loop is required...
years = Floor( integer2[0, 1] / 2048 ) + 2004;
months = Floor( Mod( integer2[0, 1], 2048 ) / 100 );
days = Mod( Mod( integer2[0, 1], 2048 ), 100 );
seconds = 60 * integer2[0, 2];
// create a table. You could also use new table, but the v1...v5 would be a little more code to type
dt = As Table(
years,
months,
days,
seconds,
float4[0, 2 :: 6],
integer4[0, 7 :: 8],
<<COLUMNNAMES></COLUMNNAMES>
Re: How to convert the specified bytes in the binary file into floating-point numbers?Thank you so much for the help of the experts!
JMP is too powerful!
JMP can be used like this!
I know too little.
Thanks again to the experts!
Re: How to convert the specified bytes in the binary file into floating-point numbers?I still have to continue to ask experts:
If you only extract the last 480 lines of data from this file, how do you modify the code?
Thanks experts!
Such data is 5070 lines in the original file. And the end of the original binary file is other text, not data.
Re: How to convert the specified bytes in the binary file into floating-point numbers?I tried to modify it like this, but it was unsuccessful.
r = N Row( years );
dt = As Table(
years,
months,
days,
seconds,
float4[r - 479 :: r, 2 :: 6], ////
integer4[r - 479 :: r, 7 :: 8], ///
<<COLUMNNAMES></COLUMNNAMES>
Re: 怎样将二进制文件中的指定字节转化为浮点数字?was there a message in the log?
all of those arrays (years,months,days,seconds) will need the same treatment: years[r-479::r], for example.
It might be easier to delete unwanted rows from the table after creating it. Try using the date column to select the range you care about.
Re: How to convert the specified bytes in the binary file into floating-point numbers?Seeing this graphic, I raise two doubts:
1. In order for the graphics to be continuous and not affected by the date interval, is there any simple way to achieve it. I will only use the row number column as the X axis
Column( "reserved" ) << Formula( Row() );dt << run formulas;Column( "reserved" ) << deleteFormula;
……
Variables( X( :reserved ), Y( :v5 ), Y( :v4 ), Y( :v3 ), Y( :v2 ), Y( :v1 ), Y( :xx ) ),

2. Actually the trading data of this data stock.
Can JMP directly make Japanese candlesticks like this one? This kind of graph can be easily produced in excel

thank you very much!