# Thread: Binary Numbers and Base 2 Calculation for Longs

1. ## Binary Numbers and Base 2 Calculation for Longs

I was recently looking into this and found it very interesting how simple it was to convert binary into a number with base 2. I understand the highest number a bite can hold is 256 and I'm assuming whenintegers hold a maximum value of 1024 it would be four bites (Each of them being added together).

Longs hold much higher numbers though, so it got me wondering, how big are longs generally? What's the highest value they can hold and how many bites are they usually?

2. Your thinking is out. A long is typically 4 bytes, but a 32bit value is more then four 8bit values.

Consider, a 1bit value can hold 0 or 1, a 2bit value can hold either 00, 01, 10 or 11, (i.e. it can hold, 0, 1, 2 or 3). Continuing, you will find a bit field can hold (2 raised to the power of the number of bits)-1.

A 32bit field can thus hold (2^32)-1 that is 0 - 4294967295, assuming it is unsigned.

>>> highest number a bite can hold is 256

This is also incorrect, an unsigned 8bit byte can hold 0 - 255, it can not hold 256.

3. Thank you for the info. All of this is still new to me, but you helped explain it alot better. Thank you.

My only last question is, if this thinking is correct.

unsigned ints hold 0 - 255... that is, all the combinations of 8 bits.
signed ints hold -127 - 127(or something close to that)... that is the total amount in 7 bits and reserving the last bit to flag the bite as either positive or negitive.

Correct?

4. Yes, an unsigned char can hold -128 to 127.

5. ## Clarification

An unsigned byte can hold values in the range [0 .. 255].
A signed byte can hold values in the range [-128 .. 127].
An unsigned short integer (2 bytes, 16 bits) can hold values in the range [0 .. 65535].
A signed short integer can hold values in the range [-32768 .. 32767].

The architecture and programming language determine what the size of the basic integer type is. In modern systems it is usually 32 bits (4 bytes), but on some (mostly older) machines, it is 16 bits (2 bytes).

6. I was recently looking into this and found it very interesting how simple it was to convert binary into a number with base 2.
What exactly is the difference between binary and base 2?

7. Nothing. Binary is base two, I was just refering to taking an byte in binary and using the calculation to convert it to a base 10 number. Looking back, I can see that statement was poorly worded.

Code:
```10011101 =

1 x 2^7 + 0 x 2^6 + 0 x 2^5 + 1 x 2^4 + 1 x 2^3 + 1 x 2^2 + 0 x 2^1 + 1 x 2^0 =
128        0         0         16        8         4         0         1    =

157```

8. signed ints hold -127 - 127(or something close to that)... that is the total amount in 7 bits and reserving the last bit to flag the bite as either positive or negitive.
100 = 01100100b
-100 != 11100100b

-100 = 10011100b

Look up 2's compliment

9. Oh thank you, that's exactly what I was looking for.

Good man, Thantos, good man. If I could PM a drink to you, I'd certainly buy you one. Since, I can't I guess I'll just drink doubley tonight.