Print Hexadecimal Numbers Of a File

This is a discussion on Print Hexadecimal Numbers Of a File within the C Programming forums, part of the General Programming Boards category; Hello, I'm now developing a home project, but before I start, I need to know how can I print the ...

  1. #1
    Trying to Learn C nathanpc's Avatar
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    72

    Question Print Hexadecimal Numbers Of a File

    Hello,
    I'm now developing a home project, but before I start, I need to know how can I print the content of a file(*.bin as example) in hexadecimal.

    I like to learn, then a good tutorial is very nice too

    Best Regards,
    Nathan Paulino Campos
    Follow Me At Twitter
    Eee PC 904HD White | Windows XP Home Edition and Linux Ubuntu Hardy Herron

    Google Talk: eeepc904@gmail.com
    ICQ: 424738586
    AIM: nathanjava

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    x for lowercase hex letters, X for uppercase letters

    Google is your friend for all kinds of C and C++ online tutorials.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    I'm not sure but I suggest reading every character and then using the printf function with %hhx to print every byte of the file.
    for example:
    char c
    while file has next
    c = next character
    printf("%hhx", c)

    That's what I would try first.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You'd probably want to fread() BUFSIZ bytes at a time ("The value of BUFSIZ is chosen on each system so as to make stream I/O efficient."). Then use printf() as above -- although that might be a little slow depending on how many characters you have.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    If Linux:

    od -t x1 filename.bin
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help me as fast as possible
    By Xbox999 in forum C Programming
    Replies: 5
    Last Post: 11-30-2009, 05:53 PM
  2. File being filled with NULLs
    By Tigers! in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2009, 05:28 PM
  3. Double print
    By thestrap in forum C Programming
    Replies: 1
    Last Post: 12-05-2007, 06:17 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21