bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Od - man page - an example


From: Cintia Del Rio
Subject: Od - man page - an example
Date: Thu, 9 Sep 2004 21:35:25 -0300

/*  A test I did about od and this things
 *  like bytes and hexa
 *  Cintia Del Rio - address@hidden
 *  9/9/2004
 
 * I´m in a Pc.... little Endian and etc*/
#include <stdio.h>

main()
{
        int numeros[4];         // int has 4 bytes 
  char str[7];  // char has just one 
        FILE *arq;
        
        // I'll just store this numbers
        numeros[0] = 0x12; 
        numeros[1] = 0x1234;
        numeros[2] = 0x123456;
        numeros[3] = 0x12345678;
        
  arq = fopen("binario.bin", "w+");
        
        fwrite( numeros, 4, 4, arq);

        //str[0] = 0xff; 
        //fwrite( str, 1, 1, arq);

  // storing bytes
        str[0] = 0x11; 
        str[1] = 0x22;
        str[2] = 0x33;
        str[3] = 0x44;
        
        fwrite( str, 1, 4, arq);

        fclose(arq);
}



*** So, I´ve stored this hexa numbers:
0x00000012
0x00001234
0x00123456
0x12345678
0x11
0x22
0x33
0x44


*** Reading the od man page, I found out the -x option could be useful to me. 

$ od -x arquivo.bin

0000000 0012 0000 1234 0000 3456 0012 5678 1234
0000020 2211 4433
0000024

As you can see, it's messy to understand. Of course I didn't want
anything like this. I was thinking that a "hexadecimal short" would
give to me TWO HEXADECIMAL DIGITS, and not two bytes. Neither me or my
friends could get it.....

I searched in google and I find another guy that have asked the same thing... 
Then I tried: 

$ od -t x1 arquivo.bin
0000000 12 00 00 00 34 12 00 00 56 34 12 00 78 56 34 12
0000020 11 22 33 44
0000024

Of course little endian looks like crazy, but never mind. 

$ od -t x4 arquivo.bin
0000000 00000012 00001234 00123456 12345678
0000020 44332211
0000024

I guess this too examples is the most common things a PC user would
like to use. Maybe they would be useful =)

Thanks =)
Cintia



-- 
Cintia Del Rio




reply via email to

[Prev in Thread] Current Thread [Next in Thread]