Given a number N and its radix base R, find whether its valid or not according to its radix base.
Find valid/invalid number for any base ranging from binary to base32.
Input : 1000101010001 Output : Valid 1000101010001 is valid binary number. Input : 0xFFFAG Output : invalid 0xFFFAG is not a valid hexa-decimal number because of character 'G' .
Method used : strspn
- strspn :
strspn(numStr, validNumber) Strspan: returns number of matching digits from character-set provided, so here it will return 1 - N, where N is length of validNumber String. numStr : And that number is provided to numStr array.
- numStr :
numStr[strspn(numStr, validNumber)] Using this number as index for numStr array, we access the digit there and it will be NULL in case string is matched and it will be non-zero if string is not matched
- !numStr : And Finally we invert the result using invert operator to match for true case !
Binary string 1000101010001 is Valid Octal string 7778A is Invalid Decimal string 45221 is Valid Hex string FAG463 is Invalid Base32 string AD22F is Valid
- Check if a number is in given base or not
- C Program to check Armstrong Number
- Lex program to check whether input number is odd or even
- C Program to Check Whether a Number is Prime or not
- C++ Program to check Prime Number
- C program to Check Whether a Number is Positive or Negative or Zero
- Program to check for a Valid IMEI Number
- C Program to Check if all digits of a number divide it
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Number of common base strings for two strings
- Program to check for ISBN
- Program to check if two strings are same or not
- Program to check if all characters have even frequency
- Program to check the validity of a Password
- Lex Program to check valid email
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.