The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 byte order of larger than 2-byte numbers
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

a_user

USA
0 Posts

Posted - 08/19/1998 :  7:05:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello Origin users!

I have written a Labtalk program to import high byte first binary data. As
indicated in the Origin Professional user's manual, I put file.byteOrder=1
before any reading or writing to the file. This has an effect only on 2-byte
numbers (short integers). What if I want to import other data types?
Is there a way to handle this problem without explicitly reading the data as a
string, changing the byte order, and finally read these bytes as longs or
floats, or whatever ... I suppose this would require to write an appropriate
DLL (be it only to keep the speed at an acceptable level).

I am very grateful for any suggestions

Yours,

Paul Ecker

a_user

USA
0 Posts

Posted - 08/19/1998 :  7:07:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Handling Reversed Byte Order

This problem was corrected in Origin 5.0.
To get correct values in version 4.1 you could take one of two approaches:

1.In-Line Processing
In this method each value is read and fixed one-by-one. Here are algorithms that handle Float and Double types after reading bytes into variable n1, n2, n3, etc. (up to n4 for Floats and n8 for Doubles).

// Reverse FLOAT
si=(n1&128)==128?-1:1;
ex=2^(((n1&127)*2+(n2&128)/128)-128);
if(ex==2^-128) ex=0;
ma=(((128+n2&127)*256+n3)*256+n4)/2^22;
n=si*ma*ex; // This is the true value

// Reverse DOUBLE
si=(n1&128)==128?-1:1;
ex=2^((((n1&127)*16)+(n2&240)/16)-1024);
ma=(((((((16+n2&15)*256+n3)*256+n4)*256+n5)*256+n6)*256+n7)*256+n8)/2^51;
n=si*ma*ex; // This is the true value

2.Post Processing
In this method a column of data is corrected by a conversion factor. This is easier for integer numbers than floating point numbers. For example, for the conversion of a column of integers you could use

col(A) = 256 * (col(A)&255) + (col(A)&65280) / 256

A conversion for Float or Double would be more complicated since it would require transforming the algorithms above into single expressions.
Any math gurus out there?

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000