freelanceprogrammers.org Forum Index » C

Big endian or little endian


View user's profile Post To page top
karthik_neyveli28@... Posted: Mon Dec 27, 2004 10:06 am


Joined: 27 Dec 2004

Posts: 1
Big endian or little endian
  Hai friends,

Can anyone write a program in C that would say

whether the given processor is Big endian or Little endian.

regards
karthik.
Reply with quote
Send private message
View user's profile Post To page top
ashwin_mittal26 Posted: Mon Dec 27, 2004 11:37 am


Joined: 27 Dec 2004

Posts: 14
Big endian or little endian
Hi all,

I am not so sure but you can use Unions for that..

With the help of unions
decalre the struct of union like

union a
{
int b,
char c,
char d
};

now assign the same address of c and d to b..

what this will do the value of b would now be assigned
to c and d (b higher 8 bits to c or d depending on big
endian or little endian)..

now print the address of c and d corresponding to the
values c and d..

Regards,
Ashwin Mittal.


--- karthik M keyan <karthik_neyveli28@...>
wrote:

>  Hai friends,
>
> Can anyone write a program in C that would say
>
> whether the given processor is Big endian or Little
> endian.
>
> regards
> karthik.




__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
Reply with quote
Send private message
View user's profile Post To page top
pnadgir2004 Posted: Mon Dec 27, 2004 11:40 am


Joined: 27 Dec 2004

Posts: 4
Big endian or little endian
One solution would be (But you should worry about this aspect unless you really want to know).
 
main()
{
    int x=1;
    if((*(char*)&x)==1)
    {//Little Endian;}
    else
    {//Big Endian;}
}karthik M keyan <karthik_neyveli28@...> wrote:

  Hai friends,Can anyone write a program in C that would say whether the given processor is Big endian or Little endian.regards karthik. To unsubscribe : programmers-town-unsubscribe@yahoogroups.com

Yahoo! India Matrimony: Find your life partner
online.
Reply with quote
Send private message
View user's profile Post To page top
snvvijayakumari Posted: Mon Dec 27, 2004 3:22 pm


Joined: 27 Dec 2004

Posts: 1
Big endian or little endian
how is that possible can u explain? how it prints whether it is a big endian or little endianAshutosh N Naik <ashutosh@...> wrote:
> Can anyone write a program in C that would say > > whether the given processor is Big endian or Little endian.if( *(long *) "200"<0)printf("Buig Endian
");else  printf?("Little Endian
");  * --     Ashutosh Naik    Teneoris Networks India Pvt. Ltd    www.teneoris.comTo unsubscribe : programmers-town-unsubscribe@yahoogroups.com

Yahoo! India Matrimony: Find your partner online.
Reply with quote
Send private message
View user's profile Post To page top
ashutosh@... Posted: Mon Dec 27, 2004 3:56 pm


Joined: 27 Dec 2004

Posts: 1
Big endian or little endian
> Can anyone write a program in C that would say
>
> whether the given processor is Big endian or Little endian.

if( *(long *) "200"<0)
printf("Buig Endian
");
else
printf?("Little Endian
");

* --
Ashutosh Naik
Teneoris Networks India Pvt. Ltd
www.teneoris.com
Reply with quote
Send private message
View user's profile Post To page top
arangasoft Posted: Tue Dec 28, 2004 2:02 pm


Joined: 28 Dec 2004

Posts: 1
Big endian or little endian
Hai Ashutosh N Naik
 
 can you explain what is big endian and little endian then only i can understand your code.please reply me soon.
cheers
Arangs
Ashutosh N Naik <ashutosh@...> wrote:
> Can anyone write a program in C that would say > > whether the given processor is Big endian or Little endian.if( *(long *) "200"<0)printf("Buig Endian
");else  printf?("Little Endian
");  * --     Ashutosh Naik    Teneoris Networks India Pvt. Ltd    www.teneoris.comTo unsubscribe : programmers-town-unsubscribe@yahoogroups.com
Do you Yahoo!? Yahoo! Mail - 250MB free storage. Do more. Manage less.
Reply with quote
Send private message
View user's profile Post To page top
taxikaps Posted: Tue Dec 28, 2004 3:58 pm


Joined: 03 Jan 2005

Posts: 10
Big endian or little endian
aranga nathan wrote:
> */ can you explain what is big endian and little endian then only i can
> understand your code.please reply me soon./*

Did you execute point 1 ?? Prefer to follow point 4 on mailing lists at
least.

For you and people who are as lazy as you.

http://www.google.co.in/search?q=big+%26+little+endian

Kapil

--
PS:
1. Google: Feel free to Google before posting. http://www.google.com

2. Posting: I suggest the group members to avoid top posting, as this
pushes the original question to the bottom. While any body would prefer
to have the main question at the top, and subsequent replies added to
the bottom, so that it is easy to comprehend the flow of information.
Embeding inside a message can be better for long replies, while a top
post may be used to post a short message.

3. Do not Hijack threads. If you need to ask a fresh question, do a
little effort of moving mouse to the New or Compose button instead of
Reply. Do not start a New message or thread by hitting "Reply" in your
mail client and changing the subject. When you do this, you mess up
other participant`s ability to read mail in a threaded fashion.

4. HTML Mail: HTML is not email, and email doesn`t contain HTML, so
please turn HTML formatting OFF in your email client. Please Do not use
italics, colors, bold, fonts, pictures, sounds, or other HTML elements.
Please use only 7-bit text when sending email to the lists.

Thanks
Reply with quote
Send private message
View user's profile Post To page top
madhukar_linux Posted: Tue Dec 28, 2004 3:58 pm


Joined: 28 Dec 2004

Posts: 3
Big endian or little endian
>if( *(long *) "200"<0)
> printf("Buig Endian
");
>else
> printf?("Little Endian
");

The program which u have wrote is working correctly..
but, whats the meaning of condition....

can u please explain it..

Rgds
Madhukar

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
Reply with quote
Send private message
View user's profile Post To page top
ashwin_mittal26 Posted: Tue Dec 28, 2004 4:25 pm


Joined: 27 Dec 2004

Posts: 14
Big endian or little endian
--- aranga nathan <arangasoft@...> wrote:

> Hai Ashutosh N Naik
>
>
>
> can you explain what is big endian and little
> endian then only i can understand your code.please
> reply me soon.
>
> cheers
>
> Arangs
>
Hi all,


In a big-endian system, the most significant value in
the sequence is stored at the lowest storage address
(i.e., first). In a little-endian system, the least
significant value in the sequence is stored first.


Regards,
Ashwin



__________________________________
Do you Yahoo!?
Dress up your holiday email, Hollywood style. Learn more.
http://celebrity.mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
pnadgir2004 Posted: Tue Dec 28, 2004 7:14 pm


Joined: 27 Dec 2004

Posts: 4
Big endian or little endian
how is that possible can u explain? how it prints whether it is a big endian or little endian
 
Guys!,
 
See this code
 
main()
{
   int x=1;
   if((*(char *)&x)==1)//Little Endian
   else  //Big endian
}
 
This is much, much easier to understand.
 
 

Yahoo! India Matrimony: Find your life partner
online.
Reply with quote
Send private message
View user's profile Post To page top
zuhaibzakaria Posted: Tue Dec 28, 2004 8:07 pm


Joined: 28 Dec 2004

Posts: 1
Big endian or little endian
wht is an endian??/



On 27 Dec 2004 04:06:09 -0000, karthik M keyan
<karthik_neyveli28@...> wrote:
>
>
> Hai friends,
>
> Can anyone write a program in C that would say
>
> whether the given processor is Big endian or Little endian.
>
> regards
> karthik.
>
>
>
> To unsubscribe : programmers-town-unsubscribe@yahoogroups.com
>
>
>
>
> Yahoo! Groups Sponsor
> ADVERTISEMENT
>
> ________________________________
> Yahoo! Groups Links
> To visit your group on the web, go to:
> http://groups.yahoo.com/group/Programmers-Town/
>
> To unsubscribe from this group, send an email to:
> Programmers-Town-unsubscribe@yahoogroups.com
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Reply with quote
Send private message
View user's profile Post To page top
ashwin_mittal26 Posted: Wed Dec 29, 2004 12:25 pm


Joined: 27 Dec 2004

Posts: 14
Big endian or little endian
--- pnadgir nadgir <pnadgir2004@...> wrote:

> how is that possible can u explain? how it prints
> whether it is a big endian or little endian
>
>
> Guys!,
>
> See this code
>
> main()
> {
> int x=1;
> if((*(char *)&x)==1)//Little Endian
> else //Big endian
> }
>
> This is much, much easier to understand.
>
>


This means that x is typecasted into char and we are
doing the AND operation with 1 i.e

IF BIG ENDIAN M/C is there then the MSB is placed onto
the leftmost part of memory address.. and when it is
typecated to char (that value 1 is lost) and you will
be having zero as a result of and operation..

like


1stly
(in case of 16bit compilers and BIG ENDIAN M/c)
RIGHT 00000001 MEMADDRESS+0
LEFT 00000000 MEMADDRESS+1


After typecasting into char
the x has value
00000000

And when and opertaion is done...
then
00000000 is the result...

Similary
For the Little ENDIAN , 16 bit compilers
X memory representation
LEFT 00000000
RIGHT 00000001


And after typecasting into char
the value of X
00000001

And when AND operation is done..
the value of X is
00000001


This is how you would be getting the result.....


Regards,
Ashwin Mittal.


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
deo31 Posted: Thu Dec 30, 2004 10:17 am


Joined: 31 Dec 2004

Posts: 5
Big endian or little endian
main
{
int x=1;
if ((char)x==1)
printf("little endian");
else
printf("bigl endian");
}
 
 
isn`t it more appropriate
ashwin mittal <ashwin_mittal26@...> wrote:
--- pnadgir nadgir <pnadgir2004@...> wrote:> how is that possible can u explain? how it prints> whether it is a big endian or little endian> >  > Guys!,>  > See this code>  > main()> {>    int x=1;>    if((*(char *)&x)==1)//Little Endian>    else  //Big endian> }>  > This is much, much easier to understand.>  >  This means that x is typecasted into char and we aredoing the AND operation with 1 i.eIF BIG ENDIAN M/C is there then the MSB is placed ontothe leftmost part of memory address.. and when it istypecated to char (that value 1 is lost) and you willbe having zero as a result of and operation..like
1stly(in case of 16bit compilers and BIG ENDIAN M/c)RIGHT 00000001 MEMADDRESS+0LEFT 00000000 MEMADDRESS+1After typecasting into charthe x has value00000000And when and opertaion is done...then 00000000 is the result...Similary For the Little ENDIAN , 16 bit compilersX memory representation LEFT 00000000RIGHT 00000001And after typecasting into charthe value of X00000001And when AND operation is done..the value of X is00000001This is how you would be getting the result.....Regards,Ashwin Mittal.__________________________________________________Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com To unsubscribe : programmers-town-unsubscribe@yahoogroups.com



Yahoo! Groups Sponsor





ADVERTISEMENT

__________________________________________________Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
sflam108 Posted: Tue Jan 04, 2005 3:08 am


Joined: 25 Jul 2003

Posts: 48
Big endian or little endian
Reply embedded...

> -----Original Message-----
> From: Zuhaib Zakaria [mailto:zuhaib.zakaria@...]
> Sent: Tuesday, December 28, 2004 8:08 AM
> To: Programmers-Town@yahoogroups.com
> Subject: Re: (PT) Big endian or little endian
>
> wht is an endian??/

Don`t bother to google?

From the words "End In". Refer to the way data are stored in memory -
whether it is "big end in" first or "little end in" first.

Memory goes from low order to high order.

"Big end in" means most significant bytes are stored first (in lowest
memory).

"Small end in" means lest significant bytes are stored first (in lowest
memory).

There is also "middle-endian", in which bytes within 16-bit word are ordered
differently from 16-bit words within 32-bit word.

HTH
Shyan
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help