I don't know what language you're using, but here are methods for bytes_to_integer and integer_to_bytes in python.
If you're using a language other than python, it should be relatively simple to translate as it uses fairly generic language constructs. You'll have to take into account the need for the integer to be a BigInt rather than an unsigned int/long/etc if necessary.
bytes_to_integer converts an array of bytes (8-bit octets) to an integer. Don't concern yourself with viewing the bytes as ascii encoded, doing the conversion with 7-bit chunks will probably be messy. Simply loop over the byte array and OR each byte into successively higher locations in the output integer.
integer_to_bytes converts a BigInt to an array of bytes. You simply apply the mask 255 to the integer to obtain the lowest 8 bits, append the obtained byte to your array, then shift the BigInt right by 8 bits, and repeat as necessary. You need to specify how long the resultant byte array should be.
def bytes_to_integer(data):
output = 0
size = len(data)
for index in range(size):
output |= data[index] << (8 * (size - 1 - index))
return output
def integer_to_bytes(integer, _bytes):
output = bytearray()
for byte in range(_bytes):
output.append((integer >> (8 * (_bytes - 1 - byte))) & 255)
return output
From there you can encode the byte array to a compatible and readable format if/as necessary