main
{
int x=1;
if ((char)x==1)
printf("little endian");
else
printf("bigl endian");
}
isn't it more appropriate
ashwin mittal <[EMAIL PROTECTED]> wrote:
--- pnadgir nadgir <[EMAIL PROTECTED]> 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..
l ike
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
To unsubscribe : [EMAIL PROTECTED]
Yahoo! Groups Sponsor
ADVERTISEMENT
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
To unsubscribe : [EMAIL PROTECTED]
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To reply to this message, go to:
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4932
Please do not reply to this message via email. (more info)
- 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:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
