0

I am giving a function to write as part of my program that takes as input a short integer num, and a short integer parity mask. The function then return the number of 1’s that are in the same position in num and in the parity mask. for example, if you enter num as 0x8 and parity mask as 0x9 then it return 1. (since 0x8 = 00001000 and 0x9 = 00001001 so they both have a 1 at position 3).

I have looked everywhere online trying to find a simple way to implement it but couldn't find anything similar to it.

Could someone please explain to me how to write this function or give some suggestion on how to start?

Thank you

user3055141
  • 109
  • 1
  • 2
  • 8
  • 2
    Use a bitwise AND to combine the two numbers, then count the number of 1 bits in the result. – Barmar Jan 31 '15 at 22:24
  • 1
    See http://stackoverflow.com/questions/109023/how-to-count-the-number-of-set-bits-in-a-32-bit-integer for how to count the bits in a number. – Barmar Jan 31 '15 at 22:26

0 Answers0