Cover by Michael Fitzgerald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

String Unpack Directives

Table A-7 lists unpack directives for String#unpack.

Table A-7. String unpack directives

Directive

Returns

Description

A

String

Removes trailing nulls and spaces

a

String

String

B

String

Extracts bits from each character (most significant bit first)

b

String

Extracts bits from each character (least significant bit first)

C

Fixnum

Extracts a character as an unsigned integer

c

Fixnum

Extracts a character as an integer

d, D

Float

Treats sizeof(double) characters as a native double

E

Float

Treats sizeof(double) characters as a double in little-endian byte order

e

Float

Treats sizeof(float) characters as a float in little-endian byte order

f, F

Float

Treats sizeof(float) characters as a native float

G

Float

Treats sizeof(double) characters as a double in network byte order

g

Float

Treats sizeof(float) characters as a float in network byte order

H

String

Extracts hex nibbles from each character (most significant bit first)

h

String

Extracts hex nibbles from each character (least significant bit first)

I

Integer

Treats sizeof(int) (modified by _) successive characters as an unsigned native integer

i

Integer

Treats sizeof(int) (modified by _) successive characters as a signed native integer

L

Integer

Treats four (modified by _) successive characters as an unsigned native long integer

l

Integer

Treats four (modified by _) successive characters as a signed native long integer

M

String

Quoted-printable

m

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required