in reply to Re^3: Practical Example of Converting Packed Value
in thread Practical Example of Converting Packed Value
I understand the bitmask and the right-shift operations much better now. This example had the concreteness and immediacy I needed. It helps me a lot to display the bitmask AND operation in binary.
Is there any reason not to use these binary constants instead of hexadecimal constants in the real program?my $day = ( $short_int & 0b0000000_0000_11111 ) ; my $month = ( $short_int & 0b0000000_1111_00000 ) >> 5 ; my $year = ( $short_int & 0b1111111_0000_00000 ) >> 9 ; my $date = sprintf "%04d-%02d-%02d", 1980 + $year, $month, $day;
I suppose in a real program, the binary/hexadecimal constants and the year 1980 would be symbolic constants; e.g., DAY_MASK and EPOCH_YEAR. Or not.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Practical Example of Converting Packed Value
by BrowserUk (Patriarch) on Dec 01, 2008 at 02:40 UTC | |
|
Re^5: Practical Example of Converting Packed Value
by ikegami (Patriarch) on Dec 01, 2008 at 04:00 UTC |