in reply to [SOLVED] How to pack and unpack 16 bit decimal with leading zero
No.
Leading zeroes are just formatting. It has nothing to do with the numeric value. So if you want leading zeroes in your output, you'll need to do it. One way would be to use something like sprintf:
$ perl -e 'printf "%05d",2911' 02911
Remember: a 16 bit number has 16 bits. Each bit is for a power of two in the result. There are no extra bits for specifying formatting. The fact that your code prints a number is because perl is converting the number to a string for you, using the default method--which is what we 'normally' want to see. If you want to specify a different format, use a formatting function (sprintf) to do it.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to pack and unpack 16 bit decimal with leading zero
by thanos1983 (Parson) on Jul 27, 2015 at 10:36 UTC |