Byte order of Long variable in Binary File

S

Slow Flyer

On reading Intiger Variables (4 bytes) from BBC micro
files, into VBA Long variables (4 bytes), I notice that
the byte order in which VBA reads the variable (using Get)
is in reverse to that used by the BBC micro.

i.e. On the disk

The BBC stores the 4 bytes in order MSB to LSB.
Decimal -2 is Hex FFFFFFFE

The VBA stores the 4 bytes in order LSB to MSB.
Decimal -2 is Hex FEFFFFFF

Can VBA be made to Put and Get the right way round?
 
J

Jonathan West

Slow Flyer said:
On reading Intiger Variables (4 bytes) from BBC micro
files, into VBA Long variables (4 bytes), I notice that
the byte order in which VBA reads the variable (using Get)
is in reverse to that used by the BBC micro.

i.e. On the disk

The BBC stores the 4 bytes in order MSB to LSB.
Decimal -2 is Hex FFFFFFFE

The VBA stores the 4 bytes in order LSB to MSB.
Decimal -2 is Hex FEFFFFFF

Can VBA be made to Put and Get the right way round?

As you have seen, it is an arbitrary choice, and no you can't get them to
change.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
K

Kevin

Are there no methods for accessing byte sized chunks of
data using VBA? If not, about the only other way I can
think of is to read the data in (backwords) as you
currently are, then pass it to a C or C++ routine which
could be designed to reverse the order of the data. C (and
C++) has routines for handling data byte by byte. That
would be a drastic step, but it would also depend on how
much you want the information the right-way-round as they
say.
 
J

Jonathan West

Kevin said:
Are there no methods for accessing byte sized chunks of
data using VBA? If not, about the only other way I can
think of is to read the data in (backwords) as you
currently are, then pass it to a C or C++ routine which
could be designed to reverse the order of the data. C (and
C++) has routines for handling data byte by byte. That
would be a drastic step, but it would also depend on how
much you want the information the right-way-round as they
say.

There are methods available to VB. If you go to the Samples page on Karl
Peterson's site http://www.mvps.org/vb/index2.html?samples.htm, ansd scrll
down to near the bottom, you'll find a sample called Twiddle.zip which
contains a whole set of bit-manipulation routines in VB. I haven't tested it
myself but I can't think of any reason it wouldn't work in VBA.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top