DIGITTOINT(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms