aboutsummaryrefslogtreecommitdiff
path: root/dialoguer/binary_conversion.py
blob: 4b8a30a46b3555ad4f0571dcc8fb0931eb0e13e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def bin_conv(data, data_type = None):
	conv_data = None
	#convert to binary 
	if type(data) == str and data_type == None:
		conv_data = bytes(data, 'utf-8')
	elif type(data) == int and data_type == None:
		conv_data = data.to_bytes(32, 'little')
	
	#convert from binary 
	elif type(data) == bytes and data_type == str:
		conv_data = data.decode()
		conv_data = conv_data.rstrip('\x00')
	elif type(data) == bytes and data_type == int:
		conv_data = int.from_bytes(data, 'little')
	elif type(data) == bytes and data_type == bool:
		conv_data = bool(data[0])

	return conv_data