Qu

read_uint16

Builtin index · File I/O

result = read_uint16(f, [endian=])

Input: f, endian · Output: result

What it is

Reads an unsigned 16-bit integer from f (file handle, opened readable). endian (string, optional, default "little", or "big") selects byte order.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = read_uint16(f, [endian=])
f —Reads an unsigned 16-bit integer from f (file handle, opened readable).
endian string, optionalendian (string, optional, default "little", or "big") selects byte order.
result number
Returns a number, or Nothing if fewer than 2 bytes remain.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

f = fopen("sample.bin", "wb")
write_int16(f, -5)
write_uint16(f, 300)
write_uint32(f, 70000)
write_double(f, 3.14159)
close(f)

g = fopen("sample.bin", "rb")
a = read_int16(g)
b = read_uint16(g)
c = read_uint32(g)
d = read_double(g)
close(g)
print("{a} {b} {c} {d}")       # -5 300 70000 3.14159

output
-5 300 70000 3.14159

from file-io