June 09, 2005
Convert some integers to BCD bytes

I needed to convert a timestamp (seconds, minutes, hours, day, month, last 2 digits of the year) into a BCD string of bytes. Here’s the Perl sub I came up with to do that:

sub bcd_timestamp_string (@) {
  # Convert given time or local time to BCD bytes
  my @time = @_ ;

  join('', map {
    pack('H*',sprintf('%02d',$_))
  } @time) ;
}
2005-06-09 Irises in front garden.jpg

 
Posted by jservice at June 09, 2005 09:47 PM
Comments