Given a HexaDecimal number, check whether it is even or odd.
Input: N = ABC7787CC87AA Output: Even Input: N = 9322DEFCD Output: Odd
- Convert the number from Hexadecimal base to Decimal base.
- Then check if the number is even or odd, which can be easily checked by dividing by 2.
Time Complexity: O(N)
Efficient approach: Since Hexadecimal numbers contain digits from 0 to 15, therefore we can simply check if the last digit is either ‘0’, ‘2’, ‘4’, ‘6’, ‘8’, ‘A'(=10), ‘C'(=12) or ‘E'(=14). If it is, then the given HexaDecimal number will be Even, else Odd.
Below is the implementation of the above approach.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if a number has an odd count of odd divisors and even count of even divisors
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Convert a binary number to hexadecimal number
- Check the divisibility of Hexadecimal numbers
- Check whether a given number is even or odd
- Program to check if a number is Positive, Negative, Odd, Even, Zero
- Check whether given floating point number is even or odd
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Check if product of digits of a number at even and odd places is equal
- Check if a N base number is Even or Odd
- Check if the number is even or odd whose digits and base (radix) is given
- Check if a Number is Odd or Even using Bitwise Operators
- Check if an Octal number is Even or Odd
- Check whether count of odd and even factors of a number are equal
- Program to Convert Hexadecimal Number to Binary
- Count Hexadecimal Number
- Reverse bytes of a Hexadecimal Number
- Number of ways to choose a pair containing an even and an odd number from 1 to N
- Smallest odd number with even sum of digits from the given number N
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.