void setup() { Serial.begin(9600); // prints title with ending line break Serial.println("Base Conversion Example"); } uint16_t x; uint8_t base = 2; // where we will place the digits of x int16_t Digits[32]; int16_t num_digits; void loop() { uint16_t y; uint16_t digit; uint16_t dig_pos; x = -1; Serial.print("Converting "); Serial.print(x, DEC); Serial.print(" into base "); Serial.print(base, DEC); Serial.println(""); y = x; dig_pos = 0; num_digits = 0; while (y > 0) { // extract out rightmost base B digit digit = y % base; y = y / base; // and put it into digit position dig_pos Digits[dig_pos] = digit; dig_pos++; // next position num_digits++; // count this digit } // now print out the digits left to right for (dig_pos = num_digits-1; dig_pos--; dig_pos >=0) { Serial.print(Digits[dig_pos], DEC); Serial.print(" "); } Serial.println(""); delay(1000); }