×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*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.

Students Click Here

Jobs

Little Endianess to Big Endianess

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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close