Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Last active February 12, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/4cd80cd18a2e9a9532f6cea323b6aa01 to your computer and use it in GitHub Desktop.
Save RickKimball/4cd80cd18a2e9a9532f6cea323b6aa01 to your computer and use it in GitHub Desktop.
zero_print - print_base<> zero filled print number using c++ template example
/*
* zero_print - print_base<> template example
*/
#include "print_t.h"
void setup() {
Serial.begin(115200);
delay(2000);
}
int indx = 0;
void loop() {
#if 0
Serial.write('0'); Serial.write('x');
Serial.println(indx, HEX);
Serial.write('0'); Serial.write('x');
Serial.println(indx, BIN);
#else
Serial.write('0'); Serial.write('x');
print_base<uint8_t, 0>(indx, HEX_, true); // zero pad 2 bytes
Serial.write('0'); Serial.write('b');
print_base<uint8_t, 0>(indx, BIN_, true); // zero pad 8 bytes
#endif
if ( ++indx > 0xff ) {
while (1);
}
}
/*
* zero_print - print_base<> template example
*/
#include "print_t.h"
void setup() {
Serial.begin(115200);
delay(2000);
}
int indx = 0;
void loop() {
#if 0
Serial.write("0"); Serial.write("x");
Serial.println(indx, HEX);
Serial.write("0"); Serial.write("x");
Serial.println(indx, BIN);
#else
Serial.write("0"); Serial.write("x");
print_base<uint8_t, 2>(indx, HEX_, true); // zero pad 2 bytes
Serial.write("0"); Serial.write("b");
print_base<uint8_t, 8>(indx, BIN_, true); // zero pad 8 bytes
#endif
if ( ++indx > 0xff ) {
while (1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment