74hc595 8bit shift register about help

i using this code but it is not working very well. Why is not very well,
little expamle;
i set the 0b00000001 it is working fine(it looks LLLLLLLH) but set the 0b00000010 it is not, bit 0 and bit 1 are equ high (it looks LLLLLLHH)
sorry for my english i hope wrote true.
pin 7: clock,pin8 data, pin 9 latch

unsigned int ds;
void setup(){
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
digitalWrite(9,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(6,LOW);
digitalWrite(6,HIGH);
HC595(0b00000001);
}

void loop(){

}


void ck(){
digitalWrite(7,HIGH);
digitalWrite(7,LOW);
}

void HC595(unsigned int sayi){
  ds=sayi && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
  ds=sayi >> 1 && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
  ds=sayi >> 2 && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
  ds=sayi >> 3 && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
  ds=sayi >> 4 && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
  ds=sayi >> 5 && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
  ds=sayi >> 6 && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
 ds=sayi >> 7 && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
  ds=0;
  digitalWrite(8,LOW);
  digitalWrite(9,HIGH);
  digitalWrite(9,LOW);
}

I'm looking for a "for"loop, but not seeing one.

byte ds,i;
void setup(){
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
digitalWrite(9,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(6,LOW); // MR pin for reset
digitalWrite(6,HIGH);
HC595(0b00000101);
}

void loop(){

}


void ck(){
digitalWrite(7,HIGH);
digitalWrite(7,LOW);
}

void HC595(byte sayi){
  for(i=0;i<8;i++){
  ds=sayi >>i && 0b00000001 ;
  digitalWrite(8,ds);
  ck();
}
  digitalWrite(9,HIGH);
  digitalWrite(9,LOW);
  }

i changed variable type because Unsined int is 4byte=32bit, Same result.

Shouldn't this

ds=sayi >>i && 0b00000001 ;

be a bitwise "and", as in:
ds= (sayi >>i) & 0b00000001 ;?

İ tryied

ds=sayi >>i;
ds = ds && 0b00000001 ;

This

ds = (sayi >>i) && (0b00000001)

This

I using 1.0.6 ide verision, i will update and tyr again maybe it is bug.

Look closer: & is one thing, && is another. And you are probably using the wrong one.

Yeah i find this now :slight_smile:

Thank you all.

&& is boolean "AND".
I writing like C codes but it have some different things.