Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > little endian , big endian , big headache

Reply
Thread Tools

little endian , big endian , big headache

 
 
manishster@gmail.com
Guest
Posts: n/a
 
      08-25-2006
I keep getting the following in my output file , regardless of whether
I convert endian-ness or not [ currently commented out in the code
below ]. How do i get "01 02 03 04" ....

Mahamannu



output : 04 03 02 01 b0 00 00


Code :
//nHeight = swap_script(nHeight);
//nWidth = swap_script(nWidth);
nHeight = 0x01020304 ;
// nHeight = (nHeight >> 24) | ((nHeight << & 0x00FF0000) |
((nHeight >> & 0x0000FF00) | (nHeight << 24) ;
printf("and the height value after changing endian-ess is ");
printf("0x%08x\n",nHeight) ;

fwrite(&nHeight, sizeof(unsigned int), 1, fOut);
fwrite(&nWidth, sizeof(unsigned int), 1, fOut);

 
Reply With Quote
 
 
 
 
manishster@gmail.com
Guest
Posts: n/a
 
      08-25-2006
As I said I have commented the code that converts the endian-ness, but
that code works, i.e. the printf in the next line does show the
opposite endian-ness, but after writing through the fwrite its always
same [ 04 03 02 01 ]

(E-Mail Removed) wrote:
> I keep getting the following in my output file , regardless of whether
> I convert endian-ness or not [ currently commented out in the code
> below ]. How do i get "01 02 03 04" ....
>
> Mahamannu
>
>
>
> output : 04 03 02 01 b0 00 00
>
>
> Code :
> //nHeight = swap_script(nHeight);
> //nWidth = swap_script(nWidth);
> nHeight = 0x01020304 ;
> // nHeight = (nHeight >> 24) | ((nHeight << & 0x00FF0000) |
> ((nHeight >> & 0x0000FF00) | (nHeight << 24) ;
> printf("and the height value after changing endian-ess is ");
> printf("0x%08x\n",nHeight) ;
>
> fwrite(&nHeight, sizeof(unsigned int), 1, fOut);
> fwrite(&nWidth, sizeof(unsigned int), 1, fOut);


 
Reply With Quote
 
 
 
 
manishster@gmail.com
Guest
Posts: n/a
 
      08-25-2006
Alright , no need to break you heads, My code was doing whats shown
below in a loop, so it would flip the endian-ness everytime , Just so
happened the output files I looked up were the ones where the
endian-ness was reset.
hope ya'll have a good day ,

just wondering though WHY this little to big and big to little isn't
part of some standard library !


http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> As I said I have commented the code that converts the endian-ness, but
> that code works, i.e. the printf in the next line does show the
> opposite endian-ness, but after writing through the fwrite its always
> same [ 04 03 02 01 ]
>
> (E-Mail Removed) wrote:
> > I keep getting the following in my output file , regardless of whether
> > I convert endian-ness or not [ currently commented out in the code
> > below ]. How do i get "01 02 03 04" ....
> >
> > Mahamannu
> >
> >
> >
> > output : 04 03 02 01 b0 00 00
> >
> >
> > Code :
> > //nHeight = swap_script(nHeight);
> > //nWidth = swap_script(nWidth);
> > nHeight = 0x01020304 ;
> > // nHeight = (nHeight >> 24) | ((nHeight << & 0x00FF0000) |
> > ((nHeight >> & 0x0000FF00) | (nHeight << 24) ;
> > printf("and the height value after changing endian-ess is ");
> > printf("0x%08x\n",nHeight) ;
> >
> > fwrite(&nHeight, sizeof(unsigned int), 1, fOut);
> > fwrite(&nWidth, sizeof(unsigned int), 1, fOut);


 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      08-25-2006
(E-Mail Removed) wrote:

> Alright , no need to break you heads



Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>



Brian (here we go again)


 
Reply With Quote
 
Lew Pitcher
Guest
Posts: n/a
 
      08-25-2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


(E-Mail Removed) wrote:
[snip]
> just wondering though WHY this little to big and big to little isn't
> part of some standard library !


Probably for the same reason that window management, robotics control,
communications stacks, and financial computations aren't part of "some
standard library"; that is to say, because they aren't needed in a
standard library, and if you /do/ need them, you can either write them
yourself or find a /non-standard/ library that supports them.

HTH
- --
Lew Pitcher

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

iD8DBQFE7z9NagVFX4UWr64RAk/6AJ9//F4uJMe7cQfCXrOwsvU97yYfSQCg5i/T
klSDY7o5kn/yeB2ErD2JFVw=
=RRqx
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      08-31-2006
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Alright , no need to break you heads, My code was doing whats shown
> below in a loop, so it would flip the endian-ness everytime , Just so
> happened the output files I looked up were the ones where the
> endian-ness was reset.
> hope ya'll have a good day ,
>
> just wondering though WHY this little to big and big to little isn't
> part of some standard library !


Because it's easy enough to write such a macro/function yourself if you
need one?

<OT> If your system supports sockets, which nearly all do these days,
then you'll almost certainly find the macros ntohl(), htonl(), htons(),
and ntohs() available in some header. These will convert between host
(native) and network (big-endian) byte orders if they differ. On POSIX
systems, you're likely to find them in <netinet/in.h>; I don't know
where they live on Windows systems.

If you don't have sockets, there's still good odds that the
implementation provides the macros bswap(), byteswap(), or something
similar. These, however, have the property that, if used on a
big-endian system, they will swap your data to little-endianness, which
probably isn't what you want. </OT>

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Little Endian to Big Endian invincible C++ 9 06-14-2005 10:21 PM
Little Endian to Big Endian for 32 bit invincible C++ 1 06-14-2005 04:20 PM
float: IEEE, big endian, little endian Ernst Murnleitner C++ 0 01-13-2004 01:48 PM
convert from BIG-ENDIAN to LITTLE-ENDIAN hicham C++ 2 07-02-2003 04:55 PM
convert from big-endian to little-endian hicham C Programming 0 06-30-2003 10:16 AM



Advertisments