in reply to selecting and converting a bitstring
You've a couple of mistakes:
$p = unpack 'v', pack 'H4', 'd262';; print $p;; 25298 $y = (($p & 0xFE00) >> 9) + 4;; $m = (($p & 0x01E0) >> 5) - 1;; $d = ($p & 0x001F);; print join '/', $y, $m, $d;; 53/5/18
Note you might need to use 'n' instead of 'v' for the unpacking depending upon the endianess of the data:
$p = unpack 'n', pack 'H4', 'd262';; print $p;; 53858 $y = (($p & 0xFE00) >> 9) + 4;; $m = (($p & 0x01E0) >> 5) - 1;; $d = ($p & 0x001F);; print join '/', $y, $m, $d;; 109/2/2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: selecting and converting a bitstring
by momo33 (Beadle) on Nov 13, 2015 at 14:00 UTC |