std.endian.big.write_i32
Show source codeHide source code
fn pub write_i32(value: Int, into: mut ByteArray, at: Int) {
if into.size - at < 4 { size_error(4) }
(into.to_pointer as Int + at as Pointer[UInt32]).0 = value.swap_bytes >>> 32
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.big
let bytes = ByteArray.filled(with: 0, times: 4)
big.write_i32(123456789, into: bytes, at: 0)
bytes # => ByteArray.from_array([7, 91, 205, 21])