Baseconvert number from Base10 to Base36

Hi
I'm looking for a small script to convert Base10 Number into Base36. The reasion is, I like to compress numbers before sending them through html POST.
For example Base10 "15000" > "BKO".

At PHP there is a funktion called string base_convert ( string $number , int $frombase , int $tobase ).

Is there anything equivalent for Arduino? I was searching, but couldn't find anything. In case there is nothing, Is it a good way of compressing data like this for sending into the internet? or is there a better way?

Thank you very much!
BR

I presume there is software at the other end to make sense of the Base36 number.

It would take even less space if you transmit the values as raw bytes. +/- 32767 only takes 2 bytes.

...R

Hi Robin,
thank you very much for your answer. I looked for raw byte, haven't heard about yet. If I understood it correctly, its like a kind of Base255 "Number". This would be greate, but I'm using a SIM900 for sending data into the internet. The communication beetween the Ardino and SIM900 is through Hardware Serial. Now I'm just "print" data like Serial.print("http://...&data1=.....) I guess in this case I can't use raw bytes or?

Thank you

If I understood it correctly, its like a kind of Base255 "Number"

No it is a base 2 number, like all the numbers stored in any computer.

I guess in this case I can't use raw bytes or?

No all communication takes place with raw bytes, it is the interpretation you put on those bytes that make it have meaning. If both ends agree on that interpretation then the information gets passed on correctly.

I checked the byte(), but it also seems to be a bit complicated :wink:

Now I'm using:

snprintf(ptMessage, BUFFER_MESSAGE, "%s/update?key=%s&field1=%i\0", tLoggerurl, tApikey, tTemp);

This BUFFER_MESSAGE is sent by Serial.print() to SIM900

would it also be ok like this:

snprintf(ptMessage, BUFFER_MESSAGE, "%s/update?key=%s&field1=%i\0", tLoggerurl, byte(tApikey), byte(tTemp));

I'm wondering whether http get is able to read the Byte Data?

@Grumpy_Mike: Thank you very much for your explanation!

I'm meassuring every hour and send these data once per day.
One measurement generates data like this: "2014090100-15000-1010-900-800-700-800" >> 37 places

So my http get contains 37x24 = 888 + url~20 = 900 places.

I thought just "ziping" the numbers by also using letters in the data string will be the easiest way of doing this.

maybee ther is another way of sending data from ardiuno throug the SIM900 into the internet?

would it also be ok like this:

Fine by me. But it won't work.

You are outputting tApikey as a string. That implies that tApikey is a NULL terminated array of chars. Why you think you can cast that to a byte escapes me.

@PaulS: Thank's for your answer, That's correct, tApikey should not become a "byte" but would it work by using byte only on the numbers within this "String" for Serial communication?

Sorry, I'm able to write small programms and know the basics in C but I'm really on my personal limit with this :wink:

With my knowledge I thougth the easiest would be to convert my data to send into ABC letters to reduce the number of letters.

But I personally can't imagine sending different "types" of data by Serial.
Maybe It makes no different sending "15000" dec or "BKO" Base36 with Letters due to amounth of data sent physicly?

Maybe It makes no different sending "15000" dec or "BKO" Base36 with Letters due to amounth of data sent physicly?

Well, sending 5 characters vs. 3 characters IS going to make a difference in your phone bill. However, converting from base 10 to base 36 is not terribly difficult. Converting from base 10 to base 16 is simply a matter of repeatedly dividing by factors of 16 that are just smaller than the number to be converted. Then, repeat for the next smaller factor of 16. That same process can be used to convert to base 36.

What range of values are you converting, and does using base 36 actually result in significantly shorter values?

tTemp suggests that the value is a temperature. Are you really dealing with temperatures that exceed 1,296 degrees?

The longest value to convert is actually the datetime like: 1409030130 (Year-Month-Day-hour-min)

the rest of the values are like normal temperature 0-1500 degree (150,0°) or humidity 0-100.

maybee I should try to build a function witch will calculate the base36 like this by hand:

1409030130 : 36 = 39139725,83 | 0,8336 = 30 > U
39139725:36 = 1087214,583 | 0,583
36 = 21 > L
1087214:36 = 30200,3889 | 0,3889 36 = 14 > E
30200:36 = 838,8889 | 0,8889
36 = 32 > W
838:36 = 23,2778 | 0,2778 *36 = 10 > A
23:36 = 0,6389 = 23 > N

NAWELU

Does anyone know a better way :wink:

Have a look at Print::printNumber in Print.cpp

void setup ()
{
  Serial.begin (9600);
  Serial.println (1409030130UL, 36); 
}

void loop ()
{
}

result
"NAWELU"

Hey AWOL!!

thank you very much! That's exactly what i was searching for!!

you saved my day :wink: !!!

1409030130UL (decimal) = 0x53fc17f5 (hex) = 4 bytes of data: 53, fc, 17, f5
NAWELU = 6 char/bytes.
I don't see what you're gaining there.

I don't see what you're gaining there.

How are you going to send those 4 bytes to the server in an GET request? Sending the 6 characters is easy.

Ok, am not familiar with that kind of transfer.