Arduino Base convert form decimal to eny base

Hi
Do you know any fast algorithm for base conversion from decimal to any other base?

The Arduino is not a decimal machine. In what form is your decimal number stored? How long is the number?

johnwasser:
The Arduino is not a decimal machine. In what form is your decimal number stored? How long is the number?

i think numbers will not get larger then int, so less then 32767.
But what do you mean not decimal machine? All computers are binary machines imo

All computers are binary machines imo

Yes. So your question about converting from some other base lacks context.

PaulS:

All computers are binary machines imo

Yes. So your question about converting from some other base lacks context.

wtf are y talking bro.

I need base converter algorithm from decimal to any base
somthing simlar

int value = 100;
int toBase = 3;

char baseChars = new char { ‘0’,‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’,
‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’,‘I’,‘J’,‘K’,‘L’,‘M’,‘N’,‘O’,‘P’,‘Q’,‘R’,‘S’,‘T’,‘U’,‘V’,‘W’,‘X’,‘Y’,‘Z’,
‘a’,‘b’,‘c’,‘d’,‘e’,‘f’,‘g’,‘h’,‘i’,‘j’,‘k’,‘l’,‘m’,‘n’,‘o’,‘p’,‘q’,‘r’,‘s’,‘t’,‘u’,‘v’,‘w’,‘x’};

char baseC = new char[toBase];
for (int i = 0; i < toBase; i++)
{
baseC = baseChars*;*
* }*
* int j = 32;*
* char[] buffer = new char[j];*
* int targetBase = baseC.Length;*
* do*
* {*
* buffer[–j] = baseC[value % targetBase];*
* value = value / targetBase;*
* }*
* while (value > 0);*
* char[] result = new char[32 - j];*
* Array.Copy(buffer, j, result, 0, 32 - j);*
* string res = new string(result);*

PaulS:

All computers are binary machines imo

Yes. So your question about converting from some other base lacks context.

Idiot award goes to yo mate :smiley: no offence but still. Have you ever heard something about the abstraction. We can represent decimal data with binary systems. How the fuck you think i can write here 3 this server and you computer knows only 0 and 1 ah?

algorytmid:
All computers are binary machines imo

The IBM 1620 was a decimal machine. Each memory location had 5 bits: four for the digit and a flag bit to indicate the end of a number. The flag bit on the first digit was used for the sign of the number so evert number was at least two digits. You had to load a multiplication table into a specific area of memory so the multiply operation would work.

algorytmid:
I need base converter algorithm from decimal to any base
somthing simlar

  int value = 100;

int toBase = 3;
           
           char baseChars = new char { ‘0’,‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’,
           ‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’,‘I’,‘J’,‘K’,‘L’,‘M’,‘N’,‘O’,‘P’,‘Q’,‘R’,‘S’,‘T’,‘U’,‘V’,‘W’,‘X’,‘Y’,‘Z’,
           ‘a’,‘b’,‘c’,‘d’,‘e’,‘f’,‘g’,‘h’,‘i’,‘j’,‘k’,‘l’,‘m’,‘n’,‘o’,‘p’,‘q’,‘r’,‘s’,‘t’,‘u’,‘v’,‘w’,‘x’};

char baseC = new char[toBase];
           for (int i = 0; i < toBase; i++)
           {
               baseC[i] = baseChars[i];
           }

int j = 32;
           char buffer = new char[j];
           int targetBase = baseC.Length;
           do
           {
               buffer[–j] = baseC[value % targetBase];
               value = value / targetBase;
           }
           while (value > 0);
           char result = new char[32 - j];
           Array.Copy(buffer, j, result, 0, 32 - j);
           string res = new string(result);

So you want help converting that code to work on an Arduino? Why didn’t you just say so?

String arbitraryBase( int value, int base) {
    static char baseChars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    String result = "";
    do (
         result = String(baseChars[value % base]) + result;  // Add on the left
         value /= base;
        } while (value != 0);
    return result;
}

Some people have the IQ of plankton. When you have a total of less than a half dozen posts on a Forum and you are lucky enough to get a response from someone with over 47000 posts and almost 600 karma points, you'd be way ahead of the game to pay heed to what he's saying rather than trying to engage him in a knife fight armed with a squirt gun.

econjack:
Some people have the IQ of plankton. When you have a total of less than a half dozen posts on a Forum and you are lucky enough to get a response from someone with over 47000 posts and almost 600 karma points, you'd be way ahead of the game to pay heed to what he's saying rather than trying to engage him in a knife fight armed with a squirt gun.

Argument from authority... srsly?
What ever bra i don't care what karma blshit he has if he dose not understand that we can represent more then 1 and 0 in binary system then one sentence bra "dont be so binary bro!"

The HP calculator CPU’s were BCD, too.

While you obviously are the next Alan Turing, we get many people who do not know that the underlying computer is binary and ask similar questions about base conversions, because they are confused about it. So don't get so huffy.

Oh, BTW, I realize you're a little short on English, but "then" refers to things that involve a time sequence, such as "I'll write this BS then I'll write some more BS." On the other hand, "than" refers to comparisons, such as "I prefer to listen to myself than to someone who still has neurons firing." Make a note of the distinction so you don't look like the idiot you are.

econjack:
Oh, BTW, I realize you’re a little short on English, but “then” refers to things that involve a time sequence, such as “I’ll write this BS then I’ll write some more BS.” On the other hand, “than” refers to comparisons, such as “I prefer to listen to myself than to someone who still has neurons firing.” Make a note of the distinction so you don’t look like the idiot you are.

all right than $)

johnwasser:

algorytmid:
All computers are binary machines imo

The IBM 1620 was a decimal machine. Each memory location had 5 bits: four for the digit and a flag bit to indicate the end of a number. The flag bit on the first digit was used for the sign of the number so evert number was at least two digits. You had to load a multiplication table into a specific area of memory so the multiply operation would work.

algorytmid:
I need base converter algorithm from decimal to any base
somthing simlar

  int value = 100;

int toBase = 3;
           
           char baseChars = new char { ‘0’,‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’,
           ‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’,‘I’,‘J’,‘K’,‘L’,‘M’,‘N’,‘O’,‘P’,‘Q’,‘R’,‘S’,‘T’,‘U’,‘V’,‘W’,‘X’,‘Y’,‘Z’,
           ‘a’,‘b’,‘c’,‘d’,‘e’,‘f’,‘g’,‘h’,‘i’,‘j’,‘k’,‘l’,‘m’,‘n’,‘o’,‘p’,‘q’,‘r’,‘s’,‘t’,‘u’,‘v’,‘w’,‘x’};

char baseC = new char[toBase];
           for (int i = 0; i < toBase; i++)
           {
               baseC[i] = baseChars[i];
           }

int j = 32;
           char buffer = new char[j];
           int targetBase = baseC.Length;
           do
           {
               buffer[–j] = baseC[value % targetBase];
               value = value / targetBase;
           }
           while (value > 0);
           char result = new char[32 - j];
           Array.Copy(buffer, j, result, 0, 32 - j);
           string res = new string(result);

So you want help converting that code to work on an Arduino? Why didn’t you just say so?

String arbitraryBase( int value, int base) {

static char baseChars = “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”;
   String result = “”;
   do (
        result = String(baseChars[value % base]) + result;  // Add on the left
        value /= base;
       } while (value != 0);
   return result;
}

Thanks your code is perfect much appreciated!

Is that String going to exist after the function exits?

Thread locked for personal attacks, bad language and crimes against spelling