Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save urmil0071/35c037b8951ca7b6f5a1569254d3a9f8 to your computer and use it in GitHub Desktop.
Save urmil0071/35c037b8951ca7b6f5a1569254d3a9f8 to your computer and use it in GitHub Desktop.
BCD-to-BINary Conversion of Unsigned Numbers using Counting Method (Slow Process)
#include <Arduino.h>
void setup()
{
int x=0x0125;
byte shift[]={0,4,8,12};
byte positionMult[]={1,10,100,1000};
int xx;
int opbin;
for (int i=0;i<=3;i++)
{
xx=x>>shift[i];
xx=xx&0x000F;
while (xx !=0)
{
opbin=opbin + positionMult[i];
xx--;
}
}
Serial.begin(9600);
Serial.println(x,HEX);
Serial.println(opbin,BIN);
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment