5

I have a .log file which is a binary file(BSC0000.log). So Viewed it in a HEX viewer(OKteta) and exported it directly in to a string(split_space.txt). With spaces in the middle as 00 DF 00 45.

The thing is that when I counted the characters in both file it showed a huge difference.

laksith@laksithPC:~/Desktop/test$ cat split_space.txt | wc -c
31617470
laksith@laksithPC:~/Desktop/test$ cat BSC0000.log | wc -c
10539157

A guess can be made that it might be because of the spaces in between . But then it should be roughly like 10539157 + 10539157/2 but how come it be this value 31617470.

but 10539157 * 3 = 31617471 that is the value from the command line +1

Laksith
  • 169
  • 2
  • 8

1 Answers1

7

A byte has 8 bits. Because hex uses 16 characters, 0-9a-f, it can only display four bits per character. It takes two hex characters to display one byte. Add to that that most characters in the hex display have a space after them and you see why the hex display takes up to three times as many bytes as the binary file.

Example

Let's create a file containing a single byte:

$ printf 'a' >afile
$ wc afile
0 1 1 afile

Now, let's display it with, for example, hexdump -C:

$ hexdump -C afile
00000000  61                                                |a|
00000001

The a character is ASCII character 61 (hex). The single byte in the file takes two characters to display in hex (and three if the hex has a space after it).

John1024
  • 13,539
  • 42
  • 51
  • does HEX has spaces in the middle? I dought it. How come hex file contain spaces as spaces are also stored in HEX values. ? – Laksith Sep 23 '15 at 04:44
  • 1
    @Laksith Yes. The hex with spaces is a _display_ format. It is done to be easy for humans to read. It is not how the data is stored in a file. – John1024 Sep 23 '15 at 04:50