#!/usr/bin/perl use strict; use warnings; my $val = 70000; print "Saving Value: $val\n"; # ENCODE my @bytes; for(my $i = 0; $i < 3; $i++) { $bytes[$i] = $val % 256; if($val) { $val = int($val / 256); } } my $savebytes = pack("ccc", @bytes); # DECODE my @newbytes = unpack("ccc", $savebytes); my $newval = 0; while(scalar @newbytes) { my $byte = pop @newbytes; $newval = $newval * 256; $newval += $byte; } print "Retrieved Value is: $newval\n";