not enough RAM! does anyone see how i can make this more RAM efficient?

does anyone see how i can make this more RAM efficient?

counter.pde (660 Bytes)

Why can't you just post the code?

sorry I'm completely new to the forum.(also i have a 5 min timer on me?) heres the source:

String myOutputString;
int myNumber = 0;

void loop() {

}

void setup() {
Serial.begin(9600);
myNumber = myBasingFunction(1);
}

int myBasingFunction(int base) {
char *symbols[62] = {"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
int decimal = myBasingFunction(base);
String conversion = "";
int myFloor;
myFloor = int(decimal / base);

while (decimal >= 1) {
String conversion;
conversion = symbols[(decimal - (base * myFloor))] +
conversion;
decimal = myFloor;

}
if (base < 11) {

myOutputString = conversion;
} else {
myOutputString = conversion;
}
return 1;

}

AWOL:
Why can't you just post the code?

another noob factor of mine. didn't quote you so I'm wasting another 5 min.

Why would you like to optimize a dysfunctional program?

Your problem is not the RAM usage.

can you tell me why its dis-functional? all i want is a decimal to base62 converter

So printing any conversion would make sense to me.

   myNumber = myBasingFunction(1);

int myBasingFunction(int base) {

Using 1 as a base does not make sense.

  return 1;Using an int returning function that returns 1 always does not make much sense to me.

int myBasingFunction(int base) {
   char *symbols[62] = {"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
   int decimal = myBasingFunction(base);

Using endless recursion will not work on any machine.

if (base < 11) {
      myOutputString = conversion;
   } else {
      myOutputString = conversion;
   }

How sensible is that?

Whandall:
So printing any conversion would make sense to me.

   myNumber = myBasingFunction(1);

int myBasingFunction(int base) {


Using 1 as a base does not make sense.

`   return 1;`Using an int returning function that returns 1 always does not make much sense to me.



int myBasingFunction(int base) {
  char *symbols[62] = {"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
  int decimal = myBasingFunction(base);


Using endless recursion will not work on **any** machine.



if (base < 11) {
      myOutputString = conversion;
  } else {
      myOutputString = conversion;
  }




How sensible is that?

oops, the first part i caught onto i think is also the main problem creating an infinite loop of heap somehow. i did return 1 because i didn't want to return an Int value and a string to an Int function. and that last part was by accident lol, the last part was supposed to look like this;
if (base < 11) {

myOutputStringInt = conversion.toInt();
myOutputString = String(myOutputStringInt);
} else {
myOutputString = conversion;
}

   char *symbols[62] = {"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};

should probably be

 char symbols[63] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

BTW. in conversions all other peolple use different 'digits' behind the 9, all other start with the uppercase letters. Normal conversion functions are designed to work only with bases up to 36.

Whandall:

   char *symbols[62] = {"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};

should probably be

 char symbols[63] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

BTW. in conversions all other peolple use different 'digits' behind the 9, all other start with the uppercase letters. Normal conversion functions are designed to work only with bases up to 36.

if i change it to that i get a 'pointers mismatch in their indirection levels'

Swoboderz:
if i change it to that i get a 'pointers mismatch in their indirection levels'

No, you don't.

Hint: it's a good idea to post the code that produces the error.

yea i forgot to remove the brackets as well sorry for that.
thing is I've done this already with javascript, but I'm having trouble porting it over. if you want to see exactly what I'm doing heres the javascript source:

var counter = 0;
var AsciiCounter;
var AsciiForLetters;
var passMyAscii;
var outputPass;
textLabel("output", outputPass);
var mySpeed = promptNum("enter 1-100");
speed(mySpeed);
Number.prototype.toBase = function (base) {
var symbols = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
var decimal = this;
var conversion = "";
if (base > symbols.length || base <= 1) {
return false;
}
while (decimal >= 1) {
conversion = symbols[(decimal - (base * Math.floor(decimal / base)))] +
conversion;
decimal = Math.floor(decimal / base);
}
console.log(parseInt(conversion));
return (base < 11) ? parseInt(conversion) : conversion;

};
setInterval(function() {

AsciiCounter = counter.toBase(62);
splitLetters(AsciiCounter);

counter++;
}

I will not translate your Java stuff.

yea i know, just put it out there in case you needed to see exactly what I'm thinking

You question in combination with the code gave me some impression of your thinking. :wink:

I already know how to convert binary data to a number in some arbitrary base,
so a Javascript implementation is not so interesting for me.

If you post code or error messages please use code tags.
(see Read this before posting a programming question ... section 6)

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile: