I am making a circuit, that will pull data out of the 4011 shift register. So far it works fine, but as my number rolls over some value, strange things start to happen.
This code will cycle all of my 4011's.
typedef unsigned long u_long;
for (u_long i = 0; i < 32; i++)
{
digitalWrite(CLOCK_in,0);
delayMicroseconds(0.2);
bool bit = digitalRead(DATA_in);
Serial.print(bit,BIN);
if (bit) out |= (1 << i);
digitalWrite(CLOCK_in,1);
}
Serial.println((u_long)out);
Serial.println((u_long)out,BIN);
From the first "print()" I get:
00000000000000010000000000000000
Which is what I am expecting as this is my input (And my goal is to convert it to unsigned long decimal - highest number is on 32bits). From the next print()
, howeer, I get 4294934528
. And I think that is not correct. From the last print()
function, where naive me expected the same answer as the first one, I get 11111111111111111000000000000000
Where is the point that I am missing? Is there some problem with the bitshift part?