1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-03 11:13:38 +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:
implicitfield 2024-04-29 18:12:36 +04:00 committed by Andrew Kaster
parent 57f0ea186e
commit f923016e0b

View File

@ -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;
}
}