mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-02 22:24:26 +00:00
AK: Add reinterpret_as_octal()
This is useful for parsing user-provided integers that should be interpreted as octals.
This commit is contained in:
parent
57f0ea186e
commit
f923016e0b
|
@ -75,4 +75,16 @@ constexpr bool is_power_of(U x)
|
|||
return true;
|
||||
}
|
||||
|
||||
template<Unsigned T>
|
||||
constexpr T reinterpret_as_octal(T decimal)
|
||||
{
|
||||
T result = 0;
|
||||
T n = 0;
|
||||
while (decimal > 0) {
|
||||
result += pow<T>(8, n++) * (decimal % 10);
|
||||
decimal /= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue