**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:

** Code goes here:**

1 |
<br />ORG 0000h<br />LJMP MAIN<br />ORG 40h<br />MAIN: MOV R0,#12 ; number to be checked whether zero or one<br /> MOV R1,#08 ; number of bits to be checked<br /> MOV A,R0<br />LOOP: RLC A ; left rotating it to check each bit of number<br /> JC LABEL1 ; if the bit is one jumping to one's counter<br /> INC R2 ; incrementing the counter for zero bit<br /> SJMP LABEL2 |

1 |
LABEL1:INC R3 ;incrementing the counter for zero bit<br />LABEL2:DJNZ R1,LOOP ; checking the counter of bits<br /> END<br /> |