# Base 256

This topic is 4065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Howdy - I'd say I'm a beginner but I've been using base 256 a lot (turning a number into a char symbol to reduce packet size) and decided, for fun, to develope a Base256 class (not completely done) and was wondering if this would be something useful for network programmers? I know it's not very hard to implement, and most often people wont be dealing with too many numbers larger than 256, but I came upon a problem resulting from data length being larger than 256 (I used one byte to tell packet size) and thought of ways to handle it. So as of now, It converts a piece of data up to, 256^6 + 256^5 + ... + 255 (adding 1 would make it 7 bytes long) and I think this would really handle nicely for those sending large numbers through the network.. and possibly other uses. What do you think?

##### Share on other sites
I'm a tad confused as to how this is a more efficient way to send a number through a network. Could you elaborate on that?

It isn't.

##### Share on other sites
Quote:
 So as of now, It converts a piece of data up to, 256^6 + 256^5 + ... + 255 (adding 1 would make it 7 bytes long) and I think this would really handle nicely for those sending large numbers through the network.. and possibly other uses.

How many bytes would an int (32-bit) occupy if stored in base 256?

##### Share on other sites
I guess I had things wrong..

I thought that it sent stuff digit by digit, i.e. 12345 would be 5 bytes, but 1 is only 1 byte..

Meh, cant blame me for trying to help =/

Edit: Btw, my original idea was to sacrifice memory/processing in favor of bandwith.

##### Share on other sites
You want to use minimum number of bits (base-2 notation) to send things over network.

For example, let's say your numbers are in range 500-1000 only.

Your range is 500, or, it takes 9 bits to fully represent such number.

Then, you need to specify how many bits you used. This is a bit harder, since you need to use variable number. Ideally, you don't even send this number across the wire, but is defined by protocol.

So, instead of sending 32 bits over network, you send only 9, or less than 30%.

The other option is to not rely on such tweaks, since you need to do a lot of weird shifting, and simply pass it through some entropy compressor, and achieve 50-75% compression.

Last option, is not to compress data. This isn't as invalid as it sounds, especially if content is very dense.

##### Share on other sites
See, I didnt even know you could send bits at a time (though I dont think you'd wanna send only a few bits in one send, but rather 100 bytes compressed to 30% of what they would use, because of the packet's header and such, right?).

Heh, well it was a fun thought of being able to help others ;) Some day I'll contribute :D

Thanks.

##### Share on other sites
The trick question I asked above: Every data stored in memory is stored in base 256, if you assume the memory is composed of 8-bit blocks. Each byte in this case represents one base-256 digit.

So if you open a file in hex editor, the hex chars are basically base 256 digits.

So there is no need to convert the numbers, you just use pointer into memory.

##### Share on other sites
My binary packet tutorial. Ideally if you design your own you can set it up to allow for a number of bits. For instance, my C++ packet can easily be updated to do just that. The boolean data type in the packet takes 1 bit, and the others use the normal 32 bit "default" sizes shown in most C++ books.
http://gpwiki.org/index.php/Binary_Packet

I reccomend learning bit operators. They are a life saver for bandwidth optimization.
Here's a tutorial. Have fun!
http://www.gmonline.demon.co.uk/cscene/CS9/CS9-02.html

##### Share on other sites
Anth/Sirisian, thank you both very much. Anth, yes, you pretty much made me realize everything is basically base 256 (I was thinking, it seemed too good NOT to be the case now)) and Sirisian thanks for pointing out the links.. I have em both open now :)

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631417
• Total Posts
2999969
×