Data types: Difference between revisions

From wiki.vg
Jump to navigation Jump to search
imported>Drainedsoul
Terminology clean up
imported>SimSonic
bool moved before byte as that it carries less information quantity
Line 10: Line 10:
! class="col3" | Notes
! class="col3" | Notes
|- class="row1"
|- class="row1"
! class="col0 centeralign" | bool
| class="col1 centeralign" | 1
| class="col2" | 0 or 1
| class="col3" | Value can be either true (0x01) or false (0x00)
|- class="row2"
! class="col0 centeralign" | byte
! class="col0 centeralign" | byte
| class="col1 centeralign" | 1
| class="col1 centeralign" | 1
| class="col2" | -128 to 127
| class="col2" | -128 to 127
| class="col3" | Signed, two's complement
| class="col3" | Signed, two's complement
|- class="row2"
|- class="row3"
! class="col0 centeralign" | short
! class="col0 centeralign" | short
| class="col1 centeralign" | 2
| class="col1 centeralign" | 2
| class="col2" | -32768 to 32767
| class="col2" | -32768 to 32767
| class="col3" | Signed, two's complement
| class="col3" | Signed, two's complement
|- class="row3"
|- class="row4"
! class="col0 centeralign" | int
! class="col0 centeralign" | int
| class="col1 centeralign" | 4
| class="col1 centeralign" | 4
| class="col2" | -2147483648 to 2147483647
| class="col2" | -2147483648 to 2147483647
| class="col3" | Signed, two's complement
| class="col3" | Signed, two's complement
|- class="row4"
|- class="row5"
! class="col0 centeralign" | long
! class="col0 centeralign" | long
| class="col1 centeralign" | 8
| class="col1 centeralign" | 8
| class="col2" | -9223372036854775808 to 9223372036854775807
| class="col2" | -9223372036854775808 to 9223372036854775807
| class="col3" | Signed, two's complement
| class="col3" | Signed, two's complement
|- class="row5"
|- class="row6"
! class="col0 centeralign" | float
! class="col0 centeralign" | float
| class="col1 centeralign" | 4
| class="col1 centeralign" | 4
Line 35: Line 40:
See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3 this]
See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3 this]
| class="col3" | Single-precision 32-bit IEEE 754 floating point
| class="col3" | Single-precision 32-bit IEEE 754 floating point
|- class="row6"
|- class="row7"
! class="col0 centeralign" | double
! class="col0 centeralign" | double
| class="col1 centeralign" | 8
| class="col1 centeralign" | 8
Line 41: Line 46:
See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3 this]
See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3 this]
| class="col3" | Double-precision 64-bit IEEE 754 floating point
| class="col3" | Double-precision 64-bit IEEE 754 floating point
|- class="row7"
|- class="row8"
! class="col0 centeralign" | string
! class="col0 centeralign" | string
| class="col1 centeralign" | ≥ 2 <br />≤ 240
| class="col1 centeralign" | ≥ 2 <br />≤ 240
| class="col2" | N/A
| class="col2" | N/A
| class="col3" | [http://en.wikipedia.org/wiki/UTF-16/UCS-2 UCS-2] big-endian string prefixed by a short containing the length of the string in [http://en.wikipedia.org/wiki/Code_point code points]. UCS-2 is a fixed-width encoding with each code point represented by a 16-bit code unit.  As it is limited to 16 bits it can only represent code points in the [https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane Basic Multilangual Plane] (U+0000 through U+FFFF inclusive).
| class="col3" | [http://en.wikipedia.org/wiki/UTF-16/UCS-2 UCS-2] big-endian string prefixed by a short containing the length of the string in [http://en.wikipedia.org/wiki/Code_point code points]. UCS-2 is a fixed-width encoding with each code point represented by a 16-bit code unit.  As it is limited to 16 bits it can only represent code points in the [https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane Basic Multilangual Plane] (U+0000 through U+FFFF inclusive).
|- class="row8"
! class="col0 centeralign" | bool
| class="col1 centeralign" | 1
| class="col2" | 0 or 1
| class="col3" | Value can be either true (0x01) or false (0x00)
|- class="row9"
|- class="row9"
! class="col0 centeralign" | metadata
! class="col0 centeralign" | metadata

Revision as of 05:10, 18 July 2013

All data sent over the network is big-endian, that is the bytes are sent from most significant byte to least significant byte. The majority of everyday computers are little-endian, therefore it may be necessary to change the endianness before sending data over the network.

Other than 'String' and 'Metadata', which are decoded with a custom function, these data formats are identical to those provided by the Java classes DataInputStream and DataOutputStream.

Size Range Notes
bool 1 0 or 1 Value can be either true (0x01) or false (0x00)
byte 1 -128 to 127 Signed, two's complement
short 2 -32768 to 32767 Signed, two's complement
int 4 -2147483648 to 2147483647 Signed, two's complement
long 8 -9223372036854775808 to 9223372036854775807 Signed, two's complement
float 4

See this

Single-precision 32-bit IEEE 754 floating point
double 8

See this

Double-precision 64-bit IEEE 754 floating point
string ≥ 2
≤ 240
N/A UCS-2 big-endian string prefixed by a short containing the length of the string in code points. UCS-2 is a fixed-width encoding with each code point represented by a 16-bit code unit. As it is limited to 16 bits it can only represent code points in the Basic Multilangual Plane (U+0000 through U+FFFF inclusive).
metadata Varies See this

Some data may be stored as an "absolute integer", which is a more precise kind of integer, and a less precise kind of double. The conversion from double to absolute integer is like so:

abs_int = (int)double * 32;

And back again:

double = (double)abs_int / 32;