DIGITTOINT(3)
π DIGITTOINT(3) β ok so bestie, let's talk about turning characters into numbers
okay so real talk, this one lives in the Library Functions Manual, and it's giving "small function, huge glow-up" energy. We're in digittoint and digittoint_l territory and honestly? iconic.
β¨ NAME β¨
digittoint, digittoint_l β convert a numeric character to its integer value
π«Ά LIBRARY π«Ά
Standard C Library (libc, -lc) β she's literally built in, no cap.
π SYNOPSIS π
#include <ctype.h>
int
digittoint(int c);
int
digittoint_l(int c, locale_t loc);
πΈ DESCRIPTION πΈ
So the digittoint() and digittoint_l() functions convert a numeric character to its corresponding integer value. And when I say numeric character I mean she can be any decimal digit or hexadecimal digit β we're inclusive over here. π With hexadecimal characters, the case of the values does not matter, so a and A are both slaying equally. periodt.
The digittoint_l() function takes an explicit locale argument, whereas the digittoint() function use the current global or per-thread locale. iykyk β one of them needs you to tell her which locale to vibe with, the other one just reads the room (the room being whatever global or per-thread locale is active).
ngl if you're out here relying on locale behaviour, double-check which one you're calling. Bestie, read the room. π
π₯ RETURN VALUES π₯
The digittoint() and digittoint_l() functions always return an integer from the range of 0 to 15. Yes, always, no exceptions, she's consistent like that. π
If the given character was not a digit as defined by isxdigit(3) or isxdigit_l(3), the function will return 0. So likeβ¦ 0 is both a legit answer and the "nope, not a digit" answer. Rip to the ambiguity but we move. π
π¦ SEE ALSO π¦
and that's the whole page bestie π«Ά this came from Debian, dated December 19, 2022 β shoutout to the source and version, mwah π
β¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms