String to BigNumber

For my project I need to set a string to a BigNumber using the BigNumber library, how would I do that?
toInt won't work for it, so I need another way. The error message is "Conversion from 'String' to non-scalar type 'BigNumber' requested"
Any suggestions?
Thanks

heres what I'm trying currently


String stringyget1 = "1011121314151617181920";
String stringyget2 = "123456789";
String stringygetwhole = stringyget2+stringyget1;

BigNumber y = stringygetwhole;
 

I suggest looking at the sizes of various numbers and see if they can accomodate the size of you number
int = 16 bits
unit32_t = 32 bits
unit64_t = 64 bits

unfortunately, those sizes aren't big enough
thanks for the suggestion though,

Please post a small but complete sketch rather than just odds and ends. I assume that you are using the BigNumber library but can't tell

Why do you need the BigNumber in a String ?

I don't know anything about the BigNumber library but you could split the string into smaller sections that fit into an int or long.

Then convert to BigNumber format, multiply by the number of 10's places, and add to re-construct the number.

sorry, here:

#include "BigNumber.h"

String stringyget1 = "1011121314151617181920";
String stringyget2 = "123456789";
String stringygetwhole = stringyget2+stringyget1;

BigNumber y = stringygetwhole;
 
void setup ()
{
  if (Serial){
int r = 0;
Serial.begin(9600);
for(r = 0; r<=20; r++){
  Serial.println();
}
Serial.print(" Number is");
 Serial.println(y);
 
}
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP); 
}
void loop(){

}

I see no reason to use Strings with BigNumber.

Maybe not, but the library appears to have a toString function judging by the examples

// function to display a big number and free it afterwards
void printBignum (BigNumber & n)
{
  char * s = n.toString ();
  Serial.println (s);
  free (s);
}  // end of printBignum

paste the actual error message, please.

The BigNumber library does not have a constructor that takes a String (capital S). You will have to use a cString.

This solves the error if you want to stay with String objects.

BigNumber y = stringygetwhole.c_str();

Look what it returns :smiley:

A BigNumber is a structure, and that function pulls out a printable ASCII C-string representing the number itself.

The library is mostly C, and exclusively uses C-strings.

typedef struct bc_struct
    {
      sign  n_sign;
      int   n_len;	/* The number of digits before the decimal point. */
      int   n_scale;	/* The number of digits after the decimal point. */
      int   n_refs;     /* The number of pointers to this number. */
      bc_num n_next;	/* Linked list for available list. */
      char *n_ptr;	/* The pointer to the actual storage.
			   If NULL, n_value points to the inside of
			   another number (bc_multiply...) and should
			   not be "freed." */
      char *n_value;	/* The number. Not zero char terminated.
			   May not point to the same place as n_ptr as
			   in the case of leading zeros generated. */
    } bc_struct;

@OP: this will get you started properly: Gammon Forum : Electronics : Microprocessors : Arbitrary precision (big number) library port for Arduino

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.