Qu

write_int16

Builtin index · File I/O

write_int16(f, n, [endian=])

Input: f, n, endian · Output: no output

What it is

Writes n (number) to f (file handle, opened writable/appendable) as a signed 16-bit integer. endian (string, optional, default "little", or "big") selects byte order.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
write_int16(f, n, [endian=])
f numberWrites n (number) to f (file handle, opened writable/appendable) as a signed 16-bit integer.
n numberWrites n (number) to f (file handle, opened writable/appendable) as a signed 16-bit integer.
endian string, optionalendian (string, optional, default "little", or "big") selects byte order.
no output—

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