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
 All Forums
 Origin Forum
 Origin Forum
 byte order of larger than 2-byte numbers

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
a_user Posted - 08/19/1998 : 7:05:00 PM
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

1   L A T E S T    R E P L I E S    (Newest First)
a_user Posted - 08/19/1998 : 7:07:00 PM
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?


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000