Skip to content
Snippets Groups Projects
Commit 82c12a09 authored by Max Horn's avatar Max Horn
Browse files

cleanup advanced demo

parent c5645170
No related branches found
No related tags found
No related merge requests found
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength){
static char bin[64];
unsigned int i=0;
while (Dec > 0) {
bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
Dec = Dec >> 1;
}
for (unsigned int j = 0; j< bitLength; j++) {
if (j >= bitLength - i) {
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
}else {
bin[j] = '0';
}
}
bin[bitLength] = '\0';
return bin;
}
...@@ -3,7 +3,7 @@ void output(unsigned long decimal, unsigned int length, unsigned int delay, unsi ...@@ -3,7 +3,7 @@ void output(unsigned long decimal, unsigned int length, unsigned int delay, unsi
if (decimal == 0) { if (decimal == 0) {
Serial.print("Unknown encoding."); Serial.print("Unknown encoding.");
} else { } else {
char* b = dec2binWzerofill(decimal, length); const char* b = dec2binWzerofill(decimal, length);
Serial.print("Decimal: "); Serial.print("Decimal: ");
Serial.print(decimal); Serial.print(decimal);
Serial.print(" ("); Serial.print(" (");
...@@ -28,8 +28,7 @@ void output(unsigned long decimal, unsigned int length, unsigned int delay, unsi ...@@ -28,8 +28,7 @@ void output(unsigned long decimal, unsigned int length, unsigned int delay, unsi
Serial.println(); Serial.println();
} }
static const char* bin2tristate(const char* bin) {
static const char* bin2tristate(char* bin) {
static char returnValue[50]; static char returnValue[50];
int pos = 0; int pos = 0;
int pos2 = 0; int pos2 = 0;
...@@ -50,3 +49,23 @@ static const char* bin2tristate(char* bin) { ...@@ -50,3 +49,23 @@ static const char* bin2tristate(char* bin) {
return returnValue; return returnValue;
} }
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) {
static char bin[64];
unsigned int i=0;
while (Dec > 0) {
bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
Dec = Dec >> 1;
}
for (unsigned int j = 0; j< bitLength; j++) {
if (j >= bitLength - i) {
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
} else {
bin[j] = '0';
}
}
bin[bitLength] = '\0';
return bin;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment