1
$\begingroup$

Given a range of hexadecimal numbers, how do I determine the total number of them that do not look like decimal numbers?

Background: I'm designing a system that auto-generates IDs that consist of four digit hexadecimal numbers but I want to exclude those that looks like decimal numbers so that users are not confused. I only want to know that with that restriction, how many IDs can the system generate (and decide if I need to increase the number of digits or not).

N.B. I can easily detect if a hexadecimal number looks like a decimal number or not though.

$\endgroup$
  • $\begingroup$ I've taken the liberty of creating and adding the tag hexadecimal. Incidentally, codegolf.stackexchange.com might enjoy this problem. $\endgroup$ – Travis Willse Jan 4 '16 at 4:14
  • $\begingroup$ If the given range is just the set of nonnegative hexadecimal numbers of $n$ digits, including leading zeros, then the number of hex numbers in which only the digits $0, \ldots, 9$ occur is $10^n$, and so the number of hex numbers excluding these is $16^n - 10^n$. For $n = 4$ this is $55536$. $\endgroup$ – Travis Willse Jan 4 '16 at 4:18
  • 3
    $\begingroup$ and DEAD or BEEF would not confuse users? $\endgroup$ – Ring Ø Jan 4 '16 at 4:21
  • $\begingroup$ Sorry, what if there's no leading zero. $\endgroup$ – Lukman Jan 4 '16 at 4:21
  • $\begingroup$ Why would there be a tag "hexadecimal"? Do we also need tags for "decimal", "binary", "octal", "base-12345", etc? The tag "number-systems" is quite sufficient. $\endgroup$ – Najib Idrissi Jan 5 '16 at 14:11
2
$\begingroup$

Number of numbers with at least an hex letter (a to f) as Travis commented $$16^{n} - 10^{n} = 55536$$

Number of numbers with no decimal at all (a to f only) $$6^{n} = 1296$$

Number of numbers with at least an hex letter (a to f) with no leading zero $$16^{n} - 10^{n} - 16^{n-1} + 10^{n-1} = 52440$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.