Binary count / want to check 8 pin from port

Hello dears..

i made a binary led counter, and at each count , i need to check witch pin is at "1" and add it to get the resul int..

for exemple : 10010101 gives "sum=4"
or: 10011111 gives "sumbit =6" see what i mean ? :face_with_monocle:

must i & (8<< pin)) ?? i 'm just a little lost !! :roll_eyes:
many thanks for your issues..


bitRead() will be your friend if you don't want to mess with masks :wink:

(and a for loop to go through all the bits)

:upside_down_face: ammazzing !!! so faster !! :partying_face:
you'r really great Mr Jackson !! so simply !! :joy:
thanks a lot... i watch for this...shure i get good issue..


have fun

The following code counts the bits in an unsigned variable x:

int cnt = 0;
byte tmp= x; //type as appropriate
while (tmp) {
  tmp = tmp & (tmp - 1);