Skip to content

Instantly share code, notes, and snippets.

@withs
Last active October 7, 2021 17:10
Show Gist options
  • Save withs/dcf1932953d11c9036ef9826eac9eca4 to your computer and use it in GitHub Desktop.
Save withs/dcf1932953d11c9036ef9826eac9eca4 to your computer and use it in GitHub Desktop.
#include "cstdint"
uint16_t intLen(uint32_t forInt) {
uint64_t factor = 1;
uint16_t intLen;
for ( intLen = 0 ; (forInt / factor) != 0 ; intLen++ ) {
factor *= 10;
}
return intLen;
}
uint32_t intReverse(uint32_t forInt) {
uint8_t factor = 1;
uint32_t res = 0;
for ( uint16_t it = 0 ; forInt != 0 ; it++ ) {
res = (res * factor) + (forInt % 10);
forInt = forInt / 10;
if ( it == 0 )
factor = 10;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment