greatly speeded up the byte conversion function