write_uint16
write_uint16(f, n, [endian=])
Input: f, n, endian · Output: no output
What it is
Writes n (number) to f (file handle, opened writable/appendable) as an unsigned 16-bit integer. endian (string, optional, default "little", or "big") selects byte order.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
write_uint16(f, n, [endian=]) | f numberWrites n (number) to f (file handle, opened writable/appendable) as an unsigned 16-bit integer.n numberWrites n (number) to f (file handle, opened writable/appendable) as an unsigned 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("records.bin", "wb")
write_double(f, 0.0)
write_uint16(f, 12)
write_double(f, 0.5)
write_uint16(f, 15)
close(f)
fields = [["t", "f64"], ["ch", "u16"]]
g = fopen("records.bin", "rb")
one = read_struct(g, fields)
close(g)
print(one.t) # 0
print(one.ch) # 12
h = fopen("records.bin", "rb")
tbl = read_structs(h, fields, 2)
close(h)
print(nrow(tbl)) # 2
print(tbl.ch) # [12, 15]
output
0 12 2 [12, 15]
from file-io
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