byte oriented programming Flashcards

1
Q

~240

A

-241

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to get complimentary

A

bit(~0b11110000&0b11111111)

(1 &laquo_space;a.bit_length()) - 1 - a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

get number of bits for integer

A

int(256).bit_length()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

int to bytes

A

int(0xcafebabe).to_bytes(length=4, byteorder=’big’)

int(0xcafebabe).to_bytes(length=4, byteorder=’little’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

get native byteorder

A

sys.byteorder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

get int from bytes

A

int.from_bytes(bytes, byteorder=”little”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

byte string from literal

A

b’some string’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

create bytes with several elements

A

bytes(5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

create bytes from iterables of integers

A

bytes([55,34,22,254])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

create bytes from string

A

bytes(string, encoding=”utf16”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

create bytes from hex string

A

bytes.fromhex(‘543433434fb0323’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

create mutable bytearray

A

bytearray()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

module for working with C structures

A

struct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

get items from bytes

A

struct.unpack_from(‘@fffHHH’, buffer)

@ - native byte order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

get iterables of items from bytes

A

struct.iter_unpack(‘@3f3H, buffer’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

get hex representation of string

A

binascii.hexlify(string)

17
Q

create memoryview

A

memoryview(bytes)

18
Q

interpreter the memoryview

A

mem[12:18].cast(‘H’).tolist()

19
Q

get memorymap file

A

with mmap.mmap(file.fileno(), 0 , access=mmap.ACCESS_READ ) as buffer: