怎样将二进制文件中的指定字节转化为浮点数字?例如将图中的第一行04——07字节转化为浮点数字,感谢专家!

正确的结果是 : 1006.27
二进制文件如下:
598A0F0548917B44F6C87B44855B7B44D7637B44DA57BE45140B000000000000
ScriptingWindows回复:如何将二进制文件中的指定字节转化为浮点数字?excel VBA

回复: 怎样将二进制文件中的指定字节转化为浮点数字?这个函数实现不了
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
有一个类似的函数,Matrix To Blob,用于转换另一个方向。
4 字节浮点数有 6 或 7 位有效数字。 8 字节浮点数有 15 或 16 位有效数字。
https://en.wikipedia.org/wiki/Single-precision_floating-point_format
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
如果您尝试使用具有方便位显示的 windows 十六进制计算器,请务必反转字节。
48917B44 -> 447B9148 -> 0 10001000 11110111001000101001000 -> 2^(136-127) * (1+1/2+1/4+1/8+1/16+0/42)...
Re: 怎样将二进制文件中的指定字节转化为浮点数字?感谢专家!
这个二进制文件中的
00、01字节——年月日
02、03字节——时分

这样代码中的是否要增加分段?再次感谢!
numbers = Blob To Matrix( blobdata, "float", 4, "little" );
Re: 如何将二进制文件中的指定字节转化为浮点数字?您可以将这四个字节处理为四个 1 字节 uint 或两个 2 字节 uint。 Uint 表示无符号整数。 使用 uint 代替浮动。 您将必须弄清楚它们如何表示时间,只有一个未解码的示例并不明显。
Re: 怎样将二进制文件中的指定字节转化为浮点数字?我还有没有能力进行这种操作。
我将整个文件上传、它有5070行这样结构的数据。
看看要如何编码?
谢谢!
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: 如何将二进制文件中的指定字节转化为浮点数字?您可以像这样制作数据图表。 似乎有一些异常值!
从 zip 文件中提取数据并绘制图表以查看异常值。
/*
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: 怎样将二进制文件中的指定字节转化为浮点数字?非常感谢专家的帮助!
JMP功能太强大了!
JMP原来可以这样使用!
我所懂得的也太少了。
再次感谢专家 !
Re: 怎样将二进制文件中的指定字节转化为浮点数字?我还是要继续向专家请教:
如果只从这个文件中提取最后 480行这样的数据、要如何修改代码?
感谢专家!
这样的数据在原文件中是 5070 行。而且原始的二进制文件的末尾部分是其它文字、不是数据。
Re: 怎样将二进制文件中的指定字节转化为浮点数字?我试着这样修改、但不成功。
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: 如何将二进制文件中的指定字节转化为浮点数字?日志中有消息吗?
所有这些数组(年、月、日、秒)都需要相同的处理:例如,years[r-479::r]。
创建表后,从表中删除不需要的行可能会更容易。 尝试使用日期列来选择您关心的范围。
Re: 怎样将二进制文件中的指定字节转化为浮点数字?看到这个图形、我提两个疑点 :
1、为了图形连续、不受日期间隔的影响、有什么简单方法实现。我只会使用行号列来作为X轴
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、其实这个数据股票的交易数据。
JMP能否直接制作象这种日本蜡烛图。在excel中能简单制作这种图

非常感谢!