# argument: short integer to convert to two bytes # return: two bytes sub short_to_bytes { local @_ = unpack("C*",pack("L",shift)); (shift, shift); } # argument: two bytes to convert into an integer # return: short integer sub bytes_to_short { my $res = 0; $res |= $bytes[1] & 0xFF; $res <<= 8; $res |= $bytes[0] & 0xFF; return $res; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Int ->Bytes -> Int
by ikegami (Patriarch) on Sep 03, 2007 at 07:20 UTC | |
Re: Int ->Bytes -> Int
by bruceb3 (Pilgrim) on Sep 03, 2007 at 06:28 UTC |