0

I’ve tried to read a npz file and it turn out the output like below

b’PK\x04\x03\x14\x00\x00\x00\x07\x00\x05\x00!\x00M\xd05\xda\xa1\xb7\
x00\x00\x00\x07\x01\x00\x00\x06\x00\x14\x00PK.npy\x01\x00\x10\x00.

I know it is unreadable for human but I really want to know what is the meaning of every character like b, PK,\ and the number on it

what is the meaning of every character on those output? like the slash or number on it? is it just random or? please help me. Thank you

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
heidii
  • 1
  • 2
  • The `PK\x03\x04\x14` at the beginning is an indicator of the file type. In this case it denotes the file is some type of compressed file. – moken Aug 26 '23 at 09:07

2 Answers2

0

Notation like the following means it is a Python bytes type:

b'......'

The P and K are just printable characters, i.e. the regular letters P and K. If you man ascii you will see that P and K are 80 and 75 in decimal.

The rest are hex representations of bytes, so \x04 just means a byte with the value 4.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

You can display your binary data as 0's and 1's like this

xx = b'PK\x04\x03\x14\x00\x00\x00\x07'

for x in xx:
     print("{:08b}".format(x))

Output:

01010000
01001011
00000100
00000011
00010100
00000000
00000000
00000000
00000111

However, looking at the data is not equivalent to understanding its meaning. It only becomes meaningful if you know the specifications of the file format.

rellachs
  • 31
  • 4
  • is it always using “x” letter? why it isn’t using y04\g06\c09\d00\g00 or anything else? – heidii Aug 26 '23 at 16:41
  • The 'x' is used to signal, that a he**X**adecimal value follows. It is somewhat clear that `\xff` refers to 255 (decimal) or 11111111 (binary). However, without the 'x' it would not be clear that `\x10` refers to 16 (decimal) or 00010000 (binary). – rellachs Aug 26 '23 at 17:37
  • so, the slash \ are using for separate every decimal number? – heidii Aug 27 '23 at 06:29
  • No, the backslash is the [escape character](https://en.wikipedia.org/wiki/Escape_character) used in python. – rellachs Aug 27 '23 at 06:41