Let's say I have these two bytes in a variable: 0xA8 0x38. ("Are these two bytes a string or a 16-bit integer?" you ask. I don't know; you tell me. This is part and parcel of my profound ignorance of this stuff. Pretend I just read the two bytes from a file into a variable.) These 16 bits are a packed representation of an MS-DOS FAT date.
I want to use Perl bitwise operations to convert this 16-bit integer (or string) to the date that it represents: 2008-05-08. Here's the conversion as I (naïvely) understand it:
How do I accomplish this conversion in Perl? All hints are welcome. Remember: I'm seeking genuine learning more than a solution to a problem -- and especially not the answer to a homework problem, I promise. IANAS!A8 38 Hexadecimal (Little Endian) 10101000 00111000 Binary (Little Endian) 38 A8 Hexadecimal (Big Endian) 00111000 10101000 Binary (Big Endian) 11111100 00000000 54321098 76543210 Bit Ruler (Indexed From 0) 0011100 0101 01000 Binary (Regrouped) 1111110 0000 00000 5432109 8765 43210 Bit Ruler (Regrouped) Year Month Day Packed Format 0011100 0101 01000 Binary 1C 05 08 Hexadecimal 28 5 8 Decimal Year = 1980 + 28 = 2008 Month = 5 Day = 8 MS-DOS FAT Date = 2008-05-08
In reply to Practical Example of Converting Packed Value by Jim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |