# c question



## cfleck (Oct 18, 2005)

I have a situation where I want to have a string of bits *much* larger than what is allowed (32 bits I believe).  I am wondering if there is a way to combine several of these 32 bit units to create one larger unit.  

I need to be able to to various operations on said unit like bit shifting and the like.  The problem is, 32 bits isn't even close to what I need.  Any ideas on how to go about it?


----------



## kainjow (Oct 18, 2005)

There is a 64 bit variable type: unsigned long long - is that what you're looking for?


----------



## boyfarrell (Oct 18, 2005)

On a related topic.

Is double equivalent to long or long long?

If I was to have an 'unsigned double' data type what would happen if it got sent a negative value, does it default to zero or just give out an error?


----------



## kainjow (Oct 18, 2005)

No double stores floating point values (i.e. the part after the decimal place) and chars/shorts/ints/longs store only whole numbers. The difference between a float and a double is that a double is twice as precise.

When you use signed integers (chars, shorts, ints, longs), the last bit (the most significant bit) is reserved to represent negative or positive for the number. When using unsigned integers, this bit is used to store the number like normal. So if you don't need negative numbers, use unsigned integers because you can store 2x as many values in the same amount of bits.

For example, a char is 8 bits. So is an unsigned char. But an unsigned char can hold values up to 2^8-1, but signed chars can only hold values up to 2^7-1 because the last bit is reserved for negative or positive (0=positive, 1=negative). This doesn't make much different with today's average desktop or laptop computers, but if you're working in embedded systems where your memory is limited, or working with binary files where every bit is important, you need to know the difference.

Oh, and doubles don't have unsigned or signed. Only integers do.


----------



## Viro (Oct 19, 2005)

I wonder why floating points can't be made unsigned. After all, there is a sign bit (check out this page for example).


----------



## boyfarrell (Oct 19, 2005)

It's a shame that there isn't a unsigned float type. And yeah, lookling at that article I can see why!


----------



## lurk (Oct 19, 2005)

You cam make them unsigned just ignore the sign bit   But really what would that get you?  If you could use that bit elsewhere one  extra bit of exponent or mantissa is not going to be worth squat.


----------



## cfleck (Oct 19, 2005)

Actually, 64 bits won't cut it.  Neither will 128 or 256.  I need several thousand.  Anything?


----------



## lurk (Oct 19, 2005)

You could use something like GMP but I don't know if that will give you all the bitwise operations need, lots of bit level operations don't translate.  What would a rotate right mean for an arbitrary length int?


----------



## boyfarrell (Oct 21, 2005)

How many decimal places do you need to calculate to?

What are you doing?


----------



## PBG4 Dude (Oct 25, 2005)

Almost sounds like you'll need to code your own bit-shifting routines if you're going beyond the 32/64 bits afforded by the registers in your processor.


----------



## cfleck (Oct 25, 2005)

I'm not using it to represent a number, exactly.  More so I've come up with a scheme to represent something else as 1s and 0s.  And while I don't need all the bit manipulations available for normal bit-strings, the left and right shift are necessary and fast.  That is why I was looking for the arbitrary length.


----------



## Captain Code (Oct 26, 2005)

Bit shifting is only fast because it's built into the CPU.  You're limited to what the CPU supports for this.

You'd have to split it up into chunks and then work with it.


----------

