Skip to content

Instantly share code, notes, and snippets.

@sdrshnptl
Last active January 2, 2021 05:21
Show Gist options
  • Save sdrshnptl/f6702ad3a1d5b74e9d2124be8e864ee5 to your computer and use it in GitHub Desktop.
Save sdrshnptl/f6702ad3a1d5b74e9d2124be8e864ee5 to your computer and use it in GitHub Desktop.
Arduino binary to decimal using bit shift
int a,b,c,d;
int i;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(i = 0; i < 16 ; i++)
{
a = i & 0x01;
b = i >> 1 & 0x01;
c = i >> 2 & 0x01;
d = i >> 3 & 0x01;
Serial.print(a);Serial.print(" ");
Serial.print(b);Serial.print(" ");
Serial.print(c);Serial.print(" ");
Serial.print(d);Serial.println(" ");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment