C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 15th, 2003, 01:50 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
big/little endian

i always think i have this down pat, and then something confuses me, in this example:
Quote:
0xbffffa40: 0x00000001 0x00000000 0x4201581e 0xdeadbeef
0xbffffa50: 0x44434241 0x48474645 0x4c4b4a49 0x504f4e4d

i am storing 2 variables, x[]="ABCDEFGH" and y = 0xdeadbeef. how come deadbeef is stored normally, and ABCDEFGH is backwards? also, an even dumber question since im so confused: in the above example, when numbering the bytes we go from left to right, but with each group of 4 bytes we go from right to left, yes? so, teh byte @ address 0xbffffa40 is 01, correct?

Last edited by infamous41md : July 15th, 2003 at 02:04 PM.

Reply With Quote
  #2  
Old July 15th, 2003, 03:02 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,977 dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 5 h 26 m 2 sec
Reputation Power: 558
Your confusion may just be an artifact of the method you used to display that data. Assuming that you are on an Intel platform, if you had told it to output a long int in hex format, then it would have switched the bytes around accordingly.

Are you able to apply your favorite hex-dump utility to this data? Notice what happens when I apply od -x and then xxd to the same source file:
Quote:
C:\dcw\PROJECTS\TEST\julian>od -x julian.c |head -4
0000000 6923 636e 756c 6564 3c20 7473 6c64 6269
0000020 682e 0d3e 230a 6e69 6c63 6475 2065 733c
0000040 6474 6f69 682e 0d3e 0d0a 760a 696f 2064
0000060 6552 6f70 7472 6928 746e 6920 6f48 7275

C:\dcw\PROJECTS\TEST\julian>xxd julian.c |head -4
0000000: 2369 6e63 6c75 6465 203c 7374 646c 6962 #include <stdlib
0000010: 2e68 3e0d 0a23 696e 636c 7564 6520 3c73 .h>..#include <s
0000020: 7464 696f 2e68 3e0d 0a0d 0a76 6f69 6420 tdio.h>....void
0000030: 5265 706f 7274 2869 6e74 2069 486f 7572 Report(int iHour

Notice how the 4-hex-digit displays in od are switched around from what they are in xxd? I believe that od is taking two bytes at a time, interpreting them as a short int, and displaying that value in hex. OTOH, xxd is taking it one byte at a time and displaying it in its proper order.

Here's a sample routine for printing a string of bytes out in hex:
Code:
// dumps contents of EEROM
void HexDump(void)
{       
    int   i, j;
    BYTE  byte, index;         
    char  s[40];
    char  s1[10];             
             
    index = 0;   
    for (i=0; i<8; i++)
    {        
        strcpy(s,"");
        for (j=0; j<16; j++)
        {         
            if (j && !(j%4))
                strcat(s," ");
            byte = EERomRead(index);
            sprintf(s1,"%02X",byte);
            strcat(s,s1);
            index++;   
        }
        printf("%s\n",s);
    }
}

Last edited by dwise1_aol : July 15th, 2003 at 03:05 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > big/little endian


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT