473,785 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ 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(nHe ight);
//nWidth = swap_script(nWi dth);
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 3149
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...@gmai l.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(nHe ight);
//nWidth = swap_script(nWi dth);
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********@gmai l.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...@gmai l.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(nHe ight);
//nWidth = swap_script(nWi dth);
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********@gmai l.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********@gmai l.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

iD8DBQFE7z9NagV FX4UWr64RAk/6AJ9//F4uJMe7cQfCXrOw svU97yYfSQCg5i/T
klSDY7o5kn/yeB2ErD2JFVw=
=RRqx
-----END PGP SIGNATURE-----

Aug 25 '06 #5
<ma********@gma il.comwrote in message
news:11******** **************@ 74g2000cwt.goog legroups.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
29014
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 under linux debian 3.0 woody Thank you for your help.
3
5193
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 or compiler? 2. In GNU gcc, { int a = {0, 1, 2, 3, 4}; bool b; float c; for (int i = 0; i < 5; i++) {
8
27465
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
6551
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
2629
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 numbers (true) or little endian (false). I tried something like the following, but never did find out if it was correct. There are two assumptions here: First, big endian direction from small to large is ordered like a string. Second, endian is...
6
3180
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 without compression). It has it's words and dwords stored in little- endian, so I do a conversion to big-endian when reading full words or dwords. I have done this because my system is big-endian. But now... what if one compiles the library in a...
23
14187
by: guthena | last post by:
Write a small C program to determine whether a machine's type is little-endian or big-endian.
2
4058
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
7050
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
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.