TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
tang_eric
NA
9
0
how to swap the high-byte and the low-byte?
Apr 29 2004 4:59 AM
there is a binary file in unix OS, I want to read it at windows OS, there must be to swap the byte sequence of the int or float type data. to int, with follow code: " short n; short i,j,k=0x00ff; i=n<<8; j=n>>8; j=j&k; n=i|j; " compile with error: " can not convert type 'int' to type 'short' " why? how about float to be swapped? in c++, that is easy! we just do it with union! like this " void TransFloat(float *f) { union { float i; unsigned char c[4]; } a; unsigned char tmp; a.i=*f; tmp=a.c[0]; a.c[0]=a.c[3]; a.c[3]=tmp; tmp=a.c[1]; a.c[1]=a.c[2]; a.c[2]=tmp; *f=a.i; return; } " but in c#, swap float type data may be difficult, somebody can help me? thx!
Reply
Answers (
2
)
Generating on-th-fly description of method.
scan file