-
Notifications
You must be signed in to change notification settings - Fork 198
Primitive data types
Mikhail Yakshin edited this page Aug 16, 2016
·
4 revisions
There are several data types predefined in Kaitai Struct, thus they are used as basic building blocks for more complex data types:
Generally, integer type specification follows this pattern: ([us])(1|2|4|8)(le|be)
- First letter —
u
ors
— specifies either unsigned or signed integer respectively - Second group —
1
,2
,4
or8
— specifies width of an integer in bytes - Third group —
le
orbe
— specifies little-endian or big-endian encoding respectively; it can be omitted if default endianness specified in meta.endian in file description.
For the sake of completeness, here's the full table of available integer types:
type |
Width, bits | Signed? | Endianness | Min value | Max value |
---|---|---|---|---|---|
u1 |
8 | No | N/A | 0 | 255 |
u2le |
16 | No | Little | 0 | 65535 |
u2be |
16 | No | Big | 0 | 65535 |
u4le |
32 | No | Little | 0 | 4294967295 |
u4be |
32 | No | Big | 0 | 4294967295 |
u8le |
64 | No | Little | 0 | 18446744073709551615 |
u8be |
64 | No | Big | 0 | 18446744073709551615 |
s1 |
8 | Yes | N/A | -128 | 127 |
s2le |
16 | Yes | Little | -32768 | 32767 |
s2be |
16 | Yes | Big | -32768 | 32767 |
s4le |
32 | Yes | Little | -2147483648 | 2147483647 |
s4be |
32 | Yes | Big | -2147483648 | 2147483647 |
s8le |
64 | Yes | Little | -9223372036854775808 | 9223372036854775807 |
s8be |
64 | Yes | Big | -9223372036854775808 | 9223372036854775807 |
Floating point number specification also follows the general pattern: f(4|8)(le|be)
- First letter —
f
— specifies floating point type - Second group —
4
or8
— specifies width of an integer in bytes - Third group —
le
orbe
— specifies little-endian or big-endian encoding respectively; it can be omitted if default endianness specified in meta.endian in file description.
The general format of float follows IEEE 754 standard.
The full list of possible floating point type is thus:
type |
Width, bits | Endianness | Mantissa bits | Exponents bits |
---|---|---|---|---|
f4be |
32 | Big | 24 | 8 |
f4le |
32 | Little | 24 | 8 |
f8be |
64 | Big | 53 | 11 |
f8le |
64 | Little | 53 | 11 |
str
strz