473,785 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

little endian or big endian ???

Write a small C program to determine whether a machine's type is
little-endian or big-endian.

Jun 28 '07
23 14186
In article <f6**********@m urdoch.hpl.hp.c om>, Chris Dollin
<ch**********@h p.comwrites
>guthena wrote:
>Write a small C program to determine whether a machine's type is
little-endian or big-endian.

OK, I've done that.
To save time please put Guthena's name at the top and email it direct
to his lecturer.

Further to save time can I email my homework direct to you in the
future?

Chris (The other one)

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 29 '07 #11
On 28 Jun, 20:01, guthena <r4r...@gmail.c omwrote:
Write a small C program to determine whether a machine's type is
little-endian or big-endian.
No

Jun 29 '07 #12
Chris Hills wrote:
In article <f6**********@m urdoch.hpl.hp.c om>, Chris Dollin
<ch**********@h p.comwrites
>>guthena wrote:
>>Write a small C program to determine whether a machine's type is
little-endian or big-endian.

OK, I've done that.
To save time please put Guthena's name at the top and email it direct
to his lecturer.
You missed my signature, yes?
Further to save time can I email my homework direct to you in the
future?
No problem.
Chris (The other one)
I thought you were the /other/ other one. /The/ Chris, of course, being
Chris Torek.

--
Chris "not Hilly, but definitely not flat" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Jun 29 '07 #13
Tejas Kokje <bi************ *@gmail.comwrot e:
On Jun 28, 12:01 pm, guthena <r4r...@gmail.c omwrote:
Write a small C program to determine whether a machine's type is
little-endian or big-endian.

Here you go..

int main()
{
int num=1;
char *cptr;

cptr = (char *)&num;

if (*cptr)
printf ("little endian\n");
else
printf ("big endian\n");

return 0;
}

Which company interview question is this ? :-D
Congratulations . You just did his homework for him. Since it's a crappy
assignment, his teacher probably thinks he did a sterling job, he'll
probably pass the course on the back of your work, and he'll end up
holding a job as a programmer _still_ thinking that this is a good
program. Which it is not; it is flawed for several reasons. I presume
_you_ will be the one to clean up after his incompetent behind, not us?

Richard
Jun 29 '07 #14
In article <f6**********@m urdoch.hpl.hp.c om>, Chris Dollin
<ch**********@h p.comwrites
>Chris Hills wrote:
>In article <f6**********@m urdoch.hpl.hp.c om>, Chris Dollin
<ch**********@ hp.comwrites
>>>guthena wrote:

Write a small C program to determine whether a machine's type is
little-endian or big-endian.

OK, I've done that.
To save time please put Guthena's name at the top and email it direct
to his lecturer.

You missed my signature, yes?
>Further to save time can I email my homework direct to you in the
future?

No problem.
>Chris (The other one)

I thought you were the /other/ other one. /The/ Chris, of course, being
Chris Torek.
Who?
Why?

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 29 '07 #15
On Jun 29, 3:22 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Tejas Kokje <binarysemaph.. .@gmail.comwrot e:
On Jun 28, 12:01 pm, guthena <r4r...@gmail.c omwrote:
Write a small C program to determine whether a machine's type is
little-endian or big-endian.
Here you go..
int main()
{
int num=1;
char *cptr;
cptr = (char *)&num;
if (*cptr)
printf ("little endian\n");
else
printf ("big endian\n");
return 0;
}
Which company interview question is this ? :-D

Congratulations . You just did his homework for him. Since it's a crappy
assignment,
This most probably isn't a homework question. Its a typical question
thats asked mostly in interviews in India.
his teacher probably thinks he did a sterling job, he'll
probably pass the course on the back of your work, and he'll end up
holding a job as a programmer _still_ thinking that this is a good
program. Which it is not; it is flawed for several reasons.
Can you tell me how it is flawed? Is it because of casting from int*
to char* ?
Jun 29 '07 #16
Chris Hills wrote:
In article <f6**********@m urdoch.hpl.hp.c om>, Chris Dollin
<ch**********@h p.comwrites
>>I thought you were the /other/ other one. /The/ Chris, of course, being
Chris Torek.

Who?
You're /surely/ not serious.
Why?
You're /surely/ not serious.

--
Chris "!?" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Jun 29 '07 #17
In article <f6**********@p c-news.cogsci.ed. ac.uk>,
Richard Tobin <ri*****@cogsci .ed.ac.ukwrote:
>*Any* test of endianness is bound to use implementation-defined or
undefined behaviour, otherwise all machines would be found to have the
same endianness!
Take an unsigned integral type. C promises no internal padding
and no trap representations . Initialize it. Take its address and cast the
address to unsigned char pointer. C defines this transformation
as being possible and that the resulting unsigned chars will
each have no internal non-value bits and no trap representations .
Now read through the unsigned char array. If the sizeof the
unsigned integral type exceeds the number of bits you initialized
to, then the value bits may be spread out in unusual ways,
most likely by all-0 unsigned char showing up, but perhaps more
complicated patterns are possible? (I'd have to go back and
re-check the values implementation clause.) But you could track
each bit by shifting it through the unsigned integral type and
seeing where it shows up in the unsigned char array.

Tracking down non-value bits and sign representation for signed
integral types -- that's harder.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Jun 29 '07 #18
Chris Dollin wrote:
Chris Hills wrote:
>In article <f6**********@m urdoch.hpl.hp.c om>, Chris Dollin
<ch**********@ hp.comwrites
>>I thought you were the /other/ other one. /The/ Chris, of course, being
Chris Torek.
Who?

You're /surely/ not serious.
>Why?

You're /surely/ not serious.
He is. And stop calling him Shirley.
--
clvrmnky <mailto:sp***** *@clevermonkey. org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jun 29 '07 #19
Spade wrote:
>
.... snip ...
>
Can you tell me how it is flawed? Is it because of casting from
int* to char* ?
For example, with a 32 bit int, you have 32 places for the most
sig. bit, 31 for the next bit, etc. for 32! total possibilities.
Yes, some combinations are more likely, but that isn't detecting,
it is discriminating.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

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

Jun 29 '07 #20

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 }
5
3149
by: manishster | last post by:
I keep getting the following in my output file , regardless of whether I convert endian-ness or not . How do i get "01 02 03 04" .... Mahamannu output : 04 03 02 01 b0 00 00
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...
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
9485
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
10161
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
9958
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8986
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
6743
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4058
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
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.