0

Find the nullification number...

For a given integer, odd_bit_value is defined as the number of bits which are '1' in odd position and even_bit_value is defined as the number of bits which are '1' in even position. Nullification is a process in which the 1's in odd position are made as zero if odd_bit_value is lesser than even_bit_value and it makes 1's in even position as zeros otherwise. In this process, number of bits to be considered for this process is equal to the minimum number of bits required to represent the number. The right most bit of the number is considered to at poistion 1. For example, if n is 12 - 1100, it becomes 4 and 15 becomes 5. Given an integer, write a C++ program to print the number after nullification. Input Format First line contains number, n Output Format Print the number after nullification

26th May 2021, 9:56 AM
Maniprakash V
Maniprakash V - avatar
3 Respuestas
+ 2
by using bitwise operator that's very easy: you only need to build a mask wich alternate 0 and 1 bits along the size (in bits) of the variable type we want to use, and then apply to the input number a bitwise 'and' the mask. bitwise 'and' keep the value of bits where bits are set and conversely delete bits where they are not: 0 & 0 = 0 0 & 1 = 0 1 & 0 = 0 1 & 1 = 1 commented solution here: https://code.sololearn.com/ckxjT7SmO6Cv/?ref=app
26th May 2021, 7:26 PM
visph
visph - avatar
0
Give me a Idea for the above problem or solution in c language
26th May 2021, 9:57 AM
Maniprakash V
Maniprakash V - avatar
0
12-1100->0100(4) 15-1111->0101(5) 100-1100100->1000100(68)
26th May 2021, 12:30 PM
Maniprakash V
Maniprakash V - avatar