aiken/primitive/int
Functions
Combining
Compare two integers.
int.compare(14, 42) == Less
int.compare(14, 14) == Equal
int.compare(42, 14) == Greater
Transforming
Interpret a Big-Endian (most-significant bytes first) ByteArray
as an Int
.
int.from_bytearray_big_endian(#"0f4240") == 1_000_000
int.from_bytearray_big_endian(#"00000f4240") == 1_000_000
int.from_bytearray_big_endian(#"0000000000000000") == 0
Interpret a Little-Endian (least-significant bytes first) ByteArray
as an Int
.
int.from_bytearray_big_endian(#"40420f") == 1_000_000
int.from_bytearray_big_endian(#"40420f0000") == 1_000_000
int.from_bytearray_big_endian(#"0000000000000000") == 0
Parse an integer from a utf-8 encoded ByteArray
, when possible.
int.from_utf8("14") == Some(14)
int.from_utf8("-42") == Some(-42)
int.from_utf8("007") == Some(7)
int.from_utf8("foo") == None
int.from_utf8("1.0") == None
int.from_utf8("1-2") == None
Compare two integers.
int.compare(14, 42) == Less
int.compare(14, 14) == Equal
int.compare(42, 14) == Greater
Interpret a Big-Endian (most-significant bytes first) ByteArray
as an Int
.
int.from_bytearray_big_endian(#"0f4240") == 1_000_000
int.from_bytearray_big_endian(#"00000f4240") == 1_000_000
int.from_bytearray_big_endian(#"0000000000000000") == 0
Interpret a Little-Endian (least-significant bytes first) ByteArray
as an Int
.
int.from_bytearray_big_endian(#"40420f") == 1_000_000
int.from_bytearray_big_endian(#"40420f0000") == 1_000_000
int.from_bytearray_big_endian(#"0000000000000000") == 0
Parse an integer from a utf-8 encoded ByteArray
, when possible.
int.from_utf8("14") == Some(14)
int.from_utf8("-42") == Some(-42)
int.from_utf8("007") == Some(7)
int.from_utf8("foo") == None
int.from_utf8("1.0") == None
int.from_utf8("1-2") == None