std.endian.little.write_i32
Show source codeHide source code
fn pub write_i32(value: Int, into: mut ByteArray, at: Int) {
if into.size - at < 4 { panic('the ByteArray must contain at least 4 bytes') }
(into.to_pointer as Int + at as Pointer[UInt32]).0 = value as UInt32
}
fn pub static write_i32(value: Int, into: mut ByteArray, at: Int)
Writes a value interpreted as a 32-bits unsigned integer into into
as a
series of bytes, starting at the index at
.
If value
is greater than the maximum value of a 32-bits unsigned integer,
the additional bits are ignored (i.e. the value wraps around).
Panics
This method panics if into
doesn't contain at least 4 values starting at
index at
.
Examples
import std.endian.little
let bytes = ByteArray.filled(with: 0, times: 4)
little.write_i32(123456789, into: bytes, at: 0)
bytes # => ByteArray.from_array([21, 205, 91, 7])