473,480 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

little endian , big endian , big headache

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 << 8) & 0x00FF0000) |
((nHeight >8) & 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);

Aug 25 '06 #1
5 3136
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 ]

manishs...@gmail.com 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 << 8) & 0x00FF0000) |
((nHeight >8) & 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);
Aug 25 '06 #2
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 !
ma********@gmail.com 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 ]

manishs...@gmail.com 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 << 8) & 0x00FF0000) |
((nHeight >8) & 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);
Aug 25 '06 #3
ma********@gmail.com 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)
Aug 25 '06 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
ma********@gmail.com 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-----

Aug 25 '06 #5
<ma********@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro 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?

<OTIf 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

Aug 31 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
28994
by: hicham | last post by:
Hi, I am looking for help, i would like to know how can i use the endian.h and config.h to convert compiled files under solaris from BIG-ENDIAN to compiled files LITTLE-ENDIAN. I am working...
3
5175
by: gary | last post by:
Hi, 1. About all C/C++ compilers, Does stack increase from high address to low address and heap grow increase from low to high? What on earth decides their increase direction, CPU architecture, OS...
8
27431
by: Perception | last post by:
Hello all, If I have a C-like data structure such that struct Data { int a; //16-bit value char; //3 ASCII characters int b; //32-bit value int c; //24-bit value }
2
6525
by: bhatia | last post by:
Hello all, If I have a C-like data structure such that struct Data { int a; //16-bit value char; //3 ASCII characters int b; //32-bit value int c; //24-bit value }
3
2605
RRick
by: RRick | last post by:
This was a question that showed up in a job interview once. (And to answer your next question: No, I didn't :)) Write a subroutine that returns a bool on whether a system supports big endian...
6
3156
by: Javier | last post by:
Hello people, I'm recoding a library that made a few months ago, and now that I'm reading what I wrote I have some questions. My program reads black and white images from a bitmap (BMP 24bpp...
23
14150
by: guthena | last post by:
Write a small C program to determine whether a machine's type is little-endian or big-endian.
2
4024
by: Ramesh | last post by:
Hi I have a structure as below on big endian based system typedef struct { unsigned long LedA:5; unsigned long LedB:4; unsigned long LedC:8;
23
7002
by: Niranjan | last post by:
I have this program : void main() { int i=1; if((*(char*)&i)==1) printf("The machine is little endian."); else printf("The machine is big endian."); }
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.