Python

struct : binary data packing & unpacking options

우리별3호 2019. 12. 27. 20:10

1. Byte Order, Size, and Alignment

 

Character

Byte order

Size

Alignment

@

native

native

native

=

native

standard

none

<

little-endian

standard

none

>

big-endian

standard

none

!

network(=big-endian)

standard

none

 

 

2. Format Characters

 

Format

C type

Python type

Standard size

x

pad type

no value

 

c

char

bytes of length 1

1

b

signed char

integer

1

B

unsigned char

integer

1

?

_Bool

bool

1

h

short

integer

2

H

unsigned short

integer

2

i

int

integer

4

I

unsigned unt

integer

4

l

long

integer

4

L

unsigned long

integer

4

q

long long

integer

8

Q

unsigned long long

integer

8

n

ssize_t

integer

 

N

size_t

integer

 

e

 

float

2

f

float

float

4

d

double

float

8

s

char[]

bytes

 

p

char[]

bytes

 

P

void*

integer

 

 

Reference

https://docs.python.org/3.7/library/struct.html