Dealing with Hex

Thank you for your code groundfungus, it almost worked well until I tested with a shorter hex value like "0x3E8", it gave me this result:
long version 3E8
byte 0 = E8
byte 1 = 3
byte 2 = 0
byte 3 = 0

When I should have this:

long version 3E8
byte 0 = E8
byte 1 = 03
byte 2 = 00
byte 3 = 00

Any suggestion of what must be changed on the code to get the right values?

Thanks