cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lala
Level VIII

How do extract parts of a binary file and evaluate them separately?

Hello!

 

For example this file with this script can get the first data is a date.

2022-07-21_12-05-43.png
How do I use a script to extract this "A2 3F 32 01"
and use a script to calculate its corresponding decimal value= 20070306

 

Thanks!

 

8 REPLIES 8
lala
Level VIII

Re: How do extract parts of a binary file and evaluate them separately?

  • This will not reverse success

bb = Load Text File( "I:\E\00820070306.zst", blob() );
ymd = Blob To Matrix( bb, "uint", 4, "little", 8 );

a=Munger(char(bb),contains(char(bb),"(")+4,12);
b=Char To blob(a, "utf-8" );;
mat=blobtomatrix(b, "uint", 4, "little", 8 );
jthi
Super User

Re: How do extract parts of a binary file and evaluate them separately?

Maybe BLOB Peek(blob, offset, length) would work? Also this might be a good watch  

-Jarmo
lala
Level VIII

Re: How do extract parts of a binary file and evaluate them separately?

Thanks!

 

2022-07-21_13-23-53.png

txnelson
Super User

Re: How do extract parts of a binary file and evaluate them separately?

Your code

bb = Load Text File( "I:\E\00820070306.zst", blob() );
ymd = Blob To Matrix( bb, "uint", 4, "little", 8 );

is creating a 2 dimensional matrix you are calling "ymd" with the values converted to decimal values.  All you have to do, is to create a new data table, then create a new column and set the values in the new column to the first column in the matrix ymd.

Names Default To Here( 1 );

bb = Load Text File( "I:\E\00820070306.zst", blob() );
ymd = Blob To Matrix( bb, "uint", 4, "little", 8 );

dt = New Table( "zst" );
dt << New Column( "col 1" );
	Column( dt, 1 ) << set values( ymd[0, 1] );

Then just repeat it for the remaining 7 columns in the matrix

txnelson_0-1658383099652.png

 

Jim
lala
Level VIII

Re: How do extract parts of a binary file and evaluate them separately?

Thank Jim!

Yes, I got this code from Craige.

This code is useful when it knows the binary data structure.

 

But this new file I don't know its data structure.I'm on a quest.

I'm wrapping this file at 00 intervals.I get the data for this.

Except for the first line which I know contains the date.

But the data starting in the second line is integer data, floating point data.But which field is a floating point, or an integer.I don't know.

2022-07-21_14-28-39.png

 

I can only restore the comparison field by field.

 

I still haven't figured it out yet.

 

txnelson
Super User

Re: How do extract parts of a binary file and evaluate them separately?

Best of luck

Jim
lala
Level VIII

Re: How do extract parts of a binary file and evaluate them separately?

 

 

How can take something in hexadecimal form and compute it as a floating point?

~D9~40~D9~CE

The following code ran incorrectly

b = Char To Blob( "~D9~40~D9~CE", "ascii~hex" );
f = Blob To Matrix( b, "float", 4, "little", 4 );

Thanks!

lala
Level VIII

Re: How do extract parts of a binary file and evaluate them separately?

  • OK

  • I just wrote the wrong code.

Thanks!