core :: Int :: hexdigit_to_byteval
self
as a hexdigit to its byte valueintrude import core::bytes
assert 0x39.hexdigit_to_byteval == 0x09
assert 0x43.hexdigit_to_byteval == 0x0C
REQUIRE: self.is_valid_hexdigit
# `self` as a hexdigit to its byte value
#
# ~~~nit
# intrude import core::bytes
# assert 0x39.hexdigit_to_byteval == 0x09
# assert 0x43.hexdigit_to_byteval == 0x0C
# ~~~
#
# REQUIRE: `self.is_valid_hexdigit`
private fun hexdigit_to_byteval: Int do
if self >= 0x30 and self <= 0x39 then
return self - 0x30
else if self >= 0x41 and self <= 0x46 then
return self - 0x37
else if self >= 0x61 and self <= 0x66 then
return self - 0x57
end
# Happens only if the requirement is not met.
# i.e. this abort is here to please the compiler
abort
end
lib/core/bytes.nit:86,2--106,4