"Now With More Salt" <coloredlikefru it@yahoo.com> wrote[color=blue]
> Suppose I wanted to go about defining a three or four bit unsigned integer
> type. How would I go about doing that? Thanks[/color]
You're going to have to provide a bit more motivation and explanation.
C++ doesn't have a 16 bit integral type, a 32 bit integral type or an 8 bit
integral type and gets along fine without them. What are you trying to do?
"Now With More Salt" <coloredlikefru it@yahoo.com> wrote in message
news:bka7te$aj8 $1@news-int.gatech.edu. ..[color=blue]
> Suppose I wanted to go about defining a three or four bit
> unsigned integer type. How would I go about doing that?[/color]
You could use a bit field embedded in a struct, but it would
not be treated as an equal with the builtins and would not
be packed optimally. C++ doesn't really let you specify the
size of types in that amount of detail. The resolution for type
sizes is sizeof(char). However, if you specify the operations
you want to support, and the expectations you have for the
type, you might be able to cobble together something that is
suitable for your purposes.
Now With More Salt <coloredlikefru it@yahoo.com> wrote in message
news:bka7te$aj8 $1@news-int.gatech.edu. ..[color=blue]
> Suppose I wanted to go about defining a three or four bit unsigned integer
> type. How would I go about doing that?[/color]
I'd create a class that wraps a std::bitset<num _of_bits>
and define whatever operations I need (e.g. arithmetic,
comparison with other types, etc.)
Now With More Salt wrote:[color=blue]
> Suppose I wanted to go about defining a three or four bit unsigned integer
> type. How would I go about doing that? Thanks
>
>[/color]
One method is to use an existing integral type that is bigger
than what you need, and perhaps typedef it.
For example, if your platform's native integral type uses
64 bits, then you would only use the "lower" 3 or 4 bits.
But if your processor has a native integral type that
uses 3 or 4 bits, then I suggest assembly language.
Comment