GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/bit/bytes_int_conversion.py at master · vspriya05/algorithms Expand file tree/ Copy pathbytes_int_conversion.pyMore file actions 35 lines (27 loc) · 652 Bytes / Copy pathbytes_int_conversion.pyFile metadata and controls35 lines (27 loc) · 652 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 from collections import deque def int_to_bytes_big_endian(num): bytestr = deque() while num > 0: # list.insert(0, ...) is inefficient bytestr.appendleft(num & 0xff) num >>= 8 return bytes(bytestr) def int_to_bytes_little_endian(num): bytestr = [] while num > 0: bytestr.append(num & 0xff) num >>= 8 return bytes(bytestr) def bytes_big_endian_to_int(bytestr): num = 0 for b in bytestr: num <<= 8 num += b return num def bytes_little_endian_to_int(bytestr): num = 0 e = 0 for b in bytestr: num += b << e e += 8 return num |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |