Uncategorized

8051 code to find number of zeros and ones in a given number…!!

Program to find number of zeros and ones in a given number.

 In this article let’s learn how to find the number of zeros and ones in a number. The easy way to find the number of zeros is by rotating each bit with carry and checking whether the carry flag is set or reset.

 Algorithm:

1) Initializing R0 to the numbers to be checked and R1 to the number of bits to be checked.
2) Left or Right rotating the number with carry.
3) Checking whether the carry has zero or one.
4) If the carry is one then incrementing the counter for one and if the carry is zero then incrementing       the counter for one.
5) Checking the number of bits and repeating the above steps till the goal is reached.
This program finds the number of zeros and ones in binary equivalent number.

 Code goes here: