//#include <iostream>
//using namespace std;
int n = 17; // The is the number I want to convert
int i = 0; // Just an incrementor
int binaryNum[6] = {0, 0, 0, 0, 0, 0}; // an array that contains the converted binary number
// remember to zero the array before each load of time
void setup() {
Serial.begin(115200);
Serial.println("starting...");
int n = 02;
decToBinary(n);
}
void loop() {
// C++ program to convert a decimal
// number to binary number
for (int j = i - 1; j >= 0; j--) {
Serial.print(binaryNum[j]);
}
// Serial.println(" "); // This reverses the binary number
//for (int j = 0; j < i; j++ ) {
// Serial.print(binaryNum[j]);
//}
delay (5000);
Serial.println(" ");
Serial.println(binaryNum[5]);
}
// function to convert decimal to binary
void decToBinary(int n)
{
// array to store binary number
// counter for binary array
//i = 0;
while (n > 0) {
// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
Serial.println(i);
return;
}