4 bit container

Hello there gentelmen,
here is my problem. I was wondering. char is 1 byte, short is 2, int is 4 bytes etc. I have a need to calculate with a lots of very large numbers. Outside of the range of all of these containers. I therefore wanna use a lot of small containers to represent ints 0 to 9 I only need a 4bits to represent 16 different values so that would do me. Is there a way to map the memmory in to a 4bits containers or is the byte the smallest you can do on average pc
Cheers
closed account (z05DSL3A)
I have a need to calculate with a lots of very large numbers.

I would look into Arbitrary-precision arithmetic (AKA bignum arithmetic).

Something like: http://gmplib.org/
char is 1 byte, short is 2, int is 4 bytes etc

Right for char, at least in the C++ definition of a byte. Wrong for the others.

The smallest memory container your machine has is 1 byte.
If you're still after a container of bits, consider a bitset:
http://cplusplus.com/reference/stl/bitset/
If his goal was to save memory, that wouldn't really help him though.
Don't be so sure. It's portable, standard, and up to the implementation to do memory optimizations.

Unbuntu 10.10:
1
2
3
4
5
6
7
8
#include <iostream>
#include <bitset>

int main() {
    std::bitset< 8 * 100 > b;
    std::cout << sizeof( b ) << std::endl;
    return 0;
}





100
Last edited on
Thank you guys for you advice
Topic archived. No new replies allowed.