Does anyone know if the modulus operator is 16 bit only?, I've been trying to extend the following routine to make it 24 bit (or 32) rather than just 16 bit.
But I've not managed to make it work, nor find any information about how many bits it will work with - I'm presuming it's down to only 16 bits?, as it fails above 65535, once a 17th bit appears the most significant digit vanishes.
The routines are fast, small, and allow you to display the digits in anyway you like, particularly useful for adding decimal points where you want them.
I've managed to get sprintf to create a string from 24 bits, but it's a lot slower and more resource heavy - and I prefer the separate variables rather than a string array.
C:
unsigned char TenK, Thou, Hund, Tens, Ones; // Decimal convert routine variables
void convert16(unsigned int numb) // Takes an unsigned integer number
{ // and converts to single
TenK = numb / 10000; // decimal digits.
Thou = (numb % 10000) / 1000;
Hund = (numb % 1000) / 100;
Tens = (numb % 100) / 10;
Ones = numb % 10;
}
But I've not managed to make it work, nor find any information about how many bits it will work with - I'm presuming it's down to only 16 bits?, as it fails above 65535, once a 17th bit appears the most significant digit vanishes.
The routines are fast, small, and allow you to display the digits in anyway you like, particularly useful for adding decimal points where you want them.
I've managed to get sprintf to create a string from 24 bits, but it's a lot slower and more resource heavy - and I prefer the separate variables rather than a string array.