1

how can i read hex values from a data file and print them out their text equivalent, for example, when viewing a binary file the characters 'ABC', will be "414243", how do i read that and print it out in text

  • 1
    in asm, everything is just bytes. You can convert the integer value of a byte to a string and use a `write` system call, like [How do I print an integer in Assembly Level Programming without printf from the c library?](https://stackoverflow.com/a/46301894). (Or converting to hex is special: you can just shift and mask to extract 4-bit digits.) Or you can have printf do it for you. – Peter Cordes Jun 29 '18 at 02:58
  • you need to find out, for the OS you're using: how to open files, read from them, write to them ('printing' can be done by writing to file handle STDOUT), how to close them, and how to convert integer to hex. – Tommylee2k Jun 29 '18 at 06:42
  • If your binary file is `414243`, just read that, and output it with some printing function which does expect ASCII/UTF-8 encoded string, those binary values are exactly that, representing ASCII string "ABC". You can run into a problem for example under windows when using the unicode variants of API, which expects string encoded in "wide char", then you must convert that 3 bytes into 6 bytes long `410042004300` to have "ABC" string encoded correctly. So your question sounds to me like you don't need to do anything, the data already are representing "ABC" string in most common encodings (UTF8). – Ped7g Jun 29 '18 at 07:01
  • oh, and if you want on the output the hexa form "414243", then you have to convert every byte value into two characters, just take upper 4 bits of value, convert those into `0-F` character and output it, and then do the same with lower 4 bits of value. The hexa vs binary has advantage that each hexa digit is exactly 4 binary digits, so every byte is exactly two hexa digits. Makes the conversion very simple and straightforward. – Ped7g Jun 29 '18 at 07:04
  • Maybe I should google more, I found what I required at https://www.muppetlabs.com/~breadbox/software/tiny/hexdump.asm.txt – Maverick Paschal Jul 02 '18 at 12:22

0 Answers0