Created
November 9, 2015 15:42
-
-
Save david50407/00e765b5f279f97b10bc to your computer and use it in GitHub Desktop.
Ruby 常用 pack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If the count is an asterisk (“*”), all remaining array elements will be converted. | |
C | Integer | Array | | |
Type | Directive | Element | Meaning | |
--------------------------------------------------------------------------------------- | |
char | c | Integer | 8-bit signed | |
short | s | Integer | 16-bit signed, native endian | |
int | l | Integer | 32-bit signed, native endian | |
long long | q | Integer | 64-bit signed, native endian | |
| | | | |
unsigned | C S L Q | Integer | unsigned; 長度同小寫 | |
| | | | |
| s> l> q> | | big endian | |
| s< l< q< | | little endian | |
| String | | | |
| Directive | | Meaning | |
--------------------------------------------------------------------------------------- | |
| A | String | arbitrary binary string (space padded, count is width) | |
| a | String | arbitrary binary string (null padded, count is width) | |
| Z | String | same as ``a'', except that null is added with * | |
| B | String | bit string (MSB first) | |
| b | String | bit string (LSB first) | |
char* | H | String | hex string (high nibble first) | |
| h | String | hex string (low nibble first) | |
| m | String | base64 encoded string (see RFC 2045, count is width) | |
| | | (if count is 0, no line feed are added, see RFC 4648) | |
| P | String | pointer to a structure (fixed-length string) | |
char** | p | String | pointer to a null-terminated string | |
| Misc. | | | |
| Directive | | Meaning | |
------------------------------------------------------------------------------ | |
| @ | --- | moves to absolute position | |
| X | --- | back up a byte | |
| x | --- | null byte | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment