|
-
July 20th, 2008, 12:55 AM
#1
cast
have a buffer of type integer (4 bytes) with 1000 elements. what is quickest method to typecast each element to short (2 bytes) before writing it a binary opened file?.
-
July 20th, 2008, 06:17 AM
#2
Re: cast
A non-portable (doesn't work for big-endian machines) could be:
Code:
int32 arr[1000];
FILE* pF;
for( int i = 0; i < 1000; ++i ) fwrite( &arr[i], 2, 1, pF );
An endian independent version requires a temporary buffer.
Edit: I assume that you're sure that the elements only contains "16-bit values"?
Last edited by S_M_A; July 20th, 2008 at 06:21 AM.
-
July 20th, 2008, 08:01 AM
#3
Re: cast
Why not just cast explicitly with "(short)" ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|