Concatenate ints

I could already solve my problem with saving large numbers (download a library to be able to save large numbers and that can also store many decimals, goodbye floats and longs). But I have another problem, and that is that I need to concatenate two "integers" (I don't know how the library can store such large numbers in a variable), the case is that that variable behaves like an int, and I need to be able to concatenate those two variables, for example:

#include "BigNumber.h"

BigNumber A = "10";
BigNumber B = "1";
BigNumber C;

C = A + B; //I need something to concat this things
Serial.print(C); //Expected: "101";

And the problem is that I already try to convert them to "Strings" and then concatenate them, that works, but the problem comes when I have to convert them back to "BigNumber", I cannot use "C.toInt ()" because I am handling numbers very big and those numbers are lost.

I need help, thanks!

This may be what you are looking for.

Sorry, but it has nothing to do with my question, what you sent is the link of the library that I am using. My question is, how can I concatenate two variables of type "BigNumber" that the library provides?

C = A * 10 + B;

Please modify the subject title of the first post and mention "BigNumber".
You should have given a link to Nick Gammon's page about BigNumber.

Why do you want to concatenate them ? What problem are you trying to solve ?

When A is always 10...99 en B is always 0 ... 9, then you can multiply A with ten and add B.

Can you show the sketch that uses the string ?
I assume you are using BigNumber::toString() ?

The BigNumber has a constructor for an integer and for a string:

BigNumber P(2);   // integer value 2 is converted to BigNumber
BigNumber Q("1234567890");   // string is converted to BigNumber

I assume that you want to store it as text? If so, there is a method toString(). I suspect that you can use it as below but don’t have time to look into it.

BigNumber A = "10";
BigNumber B = "1";
BigNumber C;

char *cTxt = c.toString();

Please note the comment in BigNumber.h

char * toString () const;  // returns number as string, [b][color=red]MUST FREE IT after use![/color][/b]

Yes, I tried to pass it as String, and it works, I can concatenate them, but the problem is that the final result it need to be a "BigNumber" variable, I can't use C.toInt() because I lose numbers.

The example I put at the beginning is the main problem I have, that is not my original code, the original is too big and in the middle of all that is the problem, I just showed you the summary problem, and instead of A = 10 and B = 1, they are much larger numbers, which I need to concatenate.

I said C.toString(), not C.toInt() :wink:

And I don't understand the problem; C is a BigNumber variable.

The concept of “concatenate” has absolutely no meaning when it comes to integers. For example, “10” cat “1” is “101”, but “1” cat “01” is “11” because “01” is the same as “1”. Until you can explain what you mean by “concatenate”, the question cannot be answered, because as posed it is nonsensical.

toString() is not the answer, because if you store “01” as an integer, it turns in “1”, and toString() will return “1”, not “01”. If you are storing the numbers as strings, then “1”, “01”, and “001”, which should all be equal, are not.

When you introduce concepts like “concatenate” that have no meaning, you must tell us what you mean.

You said they are “much bigger numbers” but you still need to explain what you are trying to do, instead of telling us that “concatenate” is the solution and you don’t know how to do it. If we knew what the problem was, there might be a better solution.

For example, if
A=12345678910111213141516171819
B=2021222324252627282930313233343536373839
it sounds like you want
123456789101112131415161718192021222324252627282930313233343536373839

I cannot understand what problem this is trying to solve. Explain that first

@hiperdoo, at least meet us half-way.

You do not want to concatenate two integers :confused: you want to concatenate two BigNumber :o
So please go back to your first post, click “Modify” and change the name for this topic. Use something with “BigNumber”.

flounder is right, you are trying to solve a nonsensical problem.
Please tell us why you want to do this. Perhaps you are trying to solve a problem that should not even be there in the first place.
We think that we smell a XY-Problem :wink: There is even a website for it: http://xyproblem.info/.

Please give a working sketch that we can try ourselves. There is also a website for that: https://snippets-r-us.com/. That website was created by Nick Gammon, the same person that turned the BigNumber into a Arduino library, which you are using.

We already gave the anser.
I tried it, and it worked.

#include <BigNumber.h>

void setup()
{
  Serial.begin( 9600);
  Serial.println();

  BigNumber::begin();

  BigNumber A = "12345678910111213141516171819";
  BigNumber B = "2021222324252627282930313233343536373839";

  char *pA = A.toString();
  char *pB = B.toString();

  char buffer[100];     // This better be big enough to hold the long string.
  strcpy( buffer, pA);
  strcat( buffer, pB);

  free( pA);
  free( pB);

  Serial.print( "As a char buffer: ");
  Serial.println( buffer);

  BigNumber C = buffer;
  Serial.print( "As a BigNumber  : ");
  Serial.println( C);
}

void loop() 
{
}