Odysseas Gabrielides wrote:
How can I use unsigned chars in a string object ?
To explain why I want to use unsigned chars:
I want to encode int and double with characters.
For exemple, to send via sockets the number 145. Instead of sending
'1','4' and '5' I thought of sending a string representing the number.
If I use char, the base will be 127. What do I mean ? I encode by doing:
buffer[0]=18 and buffer[1]=1. To decode the number, I do:
number+=buffer[i]*pow(127,i)
Well I wanted to use unsigned char to be able to increase the numerical
base, and encode larger numbers (base with unsigned char -> 255 instead
of 127)
Exemple:
With 1 char I encode: 127*1 Total: 127 numbers
With 2 char I encode: 127*2 Total: 16129 numbers
With 3 char I encode: 127*3 Total: 2048383 numbers
With 1 unsigned char I encode: 255*1 Total: 255 numbers
With 2 unsigned char I encode: 127*2 Total: 65025 numbers
With 3 unsiged char I encode: 127*3 Total: 16581375 numbers
See the difference ?
So I was just wonderinf if I could use string objects or if I had to use
old char arrays to preparethe data for sending.
For the above you should use std::vector<unsigned char>.