Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Little Endianess to Big Endianess

Status
Not open for further replies.

6HEbO1

Programmer
Jan 31, 2018
3
DE
Hi,

Does anybody now how to convert a negative 2-byte integer on a Little Endian Operating System/CPU to a machine with Big Endian (Motorola)??

Any help would be welcome.

Kind regards,
6HEbo1
 
What compiler/OS are you using? Which version of Fortran are you using? This is quite easy in C, a bit more cummbersome in Fortran.

What form is the data in: is it in code or in a binary file?

How do you wish to output the data: writing to hardware, writing to a binary file or output as numbers?
 
Hi xwb,

In and output only in code. In Fortran 90 on a VMS system.

Like:

X and Y as var in code

X = -14
Y = ??

Y will be send to the BE machine

What I've read now it should be for negative numbers the 2th complement + 1 and then a byteswap? Is that correct? If so I'll try that myself.

 
That is correct for converting a +ve to a -ve number. Does your compiler have the functions ishft, iand, ior
Code:
!       ,-- move bottom 8 bits to the top
!       |                       ,-- move top 8 bits to the bottom           
y = ior(ishft(iand(x, 255), 8), ishft(x, -8))
!
! print numbers in hex to ensure byteswap
print '(I6, 1X, Z4, 1X, I6, 1X, Z4)', x, x, y, y
 
Yes it does have these functions.

Thx!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top