10 examples of 'convert int to byte python' in Python

Every line of 'convert int to byte python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
9def byte_to_int(byte): # already byte
10 return byte
79def int2byte(c):
80 return bytes([c])
115def bytes_to_int(bytes):
116 return reduce(lambda s, x: (s << 8) + x, bytearray(bytes))
292def _int_convert(value: int, bit_size: int, signed: bool) -> int:
293 value &= (1 << bit_size) - 1
294 if signed and (value & (1 << (bit_size - 1))):
295 value -= 1 << bit_size
296 return value
73def bytes_from_int(val):
74 buf = []
75 while val:
76 val, remainder = divmod(val, 256)
77 buf.append(remainder)
78
79 buf.reverse()
80 return struct.pack('%sB' % len(buf), *buf)
352def ToChar(byte):
353 """Convert a byte to a character
354
355 This is useful because in Python 2 bytes is an alias for str, but in
356 Python 3 they are separate types. This function converts an ASCII value to
357 a value with the appropriate type in either case.
358
359 Args:
360 byte: A byte or str value
361 """
362 return chr(byte) if type(byte) != str else byte
226def _bytes_to_int(b):
227 return int(codecs.encode(b, "hex"), 16)
481def byteb(byte):
482 return bstructx.byteb(byte)
8def _integer_to_bytes(integer, _bytes=16):
9 output = bytearray()
10 _bytes /= 2
11 for byte in range(_bytes):
12 output.append((integer >> (8 * (_bytes - 1 - byte))) & 255)
13 return output
55def int_to_bytes(int, word_size):
56 b = ''
57 while int > 0:
58 b = chr(int & 0xFF) + b
59 int = int >> 8
60 b = ((word_size - len(b)) * '\x00') + b
61 return b

Related snippets