×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Little Endianess to Big Endianess

## Little Endianess to Big Endianess

(OP)
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

### RE: Little Endianess to Big Endianess

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?

### RE: Little Endianess to Big Endianess

(OP)
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.

### RE: Little Endianess to Big Endianess

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 

### RE: Little Endianess to Big Endianess

(OP)
Yes it does have these functions.

Thx!

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!