Home Gadgetman Forum Book Reviews Links Contact me X-UFO
Gadgets Processors Programming School Old news
When working with computers, you will sooner or later run into some strange numbers...

I will try to explain them here.

The first that you have to know is the bit(note the non-capitalised b). this is the smallest unit. It can be either 0 or 1, also known as Off or On, and even False and True...

The next step up is the nibble(It's true! Honest!) that consists of 4 bits.

The next up from that is the famous Byte.(Please note the Capital B) This consists of 8 bits. (or 2 nibbles :-)

Got that? Good...
Now for some calculations. If one bit give 2 states(0/1) how many does 4 or 8 bit give?

The answer: 16 and 256. How?
Decb3b2b1b0Hex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

Everyone should be able to understand the first column... Most of you should also be able to understand the structure of the next four columns. (the rightmost is the least significant. it counts from 0 to 1, and when it overflows the next column is incremented, just as when counting upwards from 8 to 9 and then to... )

Now you understand binary, or as it's also known: Base 2. (Our normal decimal system is known as Base 10)

And the prize goes to those who guessed that the last column shows the hexadecimal(shortened to Hex) also known as Base 16...

And the more clever types have probably realised what is so marvelous with the Hex system.

It's very easy to convert to and from Binary... (What? don't see the advantage?) And if that don't help, consider the fact that on the Digital PDP 11(and on some other early stoneage computers) they used Octal also known as Base 8. The reason being that it was closer to Decimal... (Yes, I have done it. Assembly programming on it! 8inch floppies and Virtual memory!) Another interresting fact about Hex is that there's ALWAYS two digits to every Byte.

Now for some interresting facts about memory.

Have you heard about a KB? (KiloByte) How many Bytes(mind the capital B) do you think that is?

The correct answer is 1024! Anyone saying 1000 can please check how much you can get with 10 bits. (Actually: 0 to 1023, or 1024 distinct values...) 1KB is also written as 0x400 in Hex.

Now, if you wanted to find the 4'th byte above 1KB you would write 0x403. (remember we're working with 0- 1023+4 so the first above 1KB is actually 1024)

It's time to go further. The next datasize up is the Word. That is 16bits or 2Bytes. That gives a possible range from 0 to 65535... (It's easier with Hex: 0 to FFFF :-) Ever heard about 64KB? Now, to make it even more fun: an Integer is usually a Word size variable. But a Integer goes from -32768 to 32767. How does one do that? If you write the positive value as Hex(0x7FFF) you will see that it don't use the highest bit. And here's the joker: -1 is written 0xFFFF, -2 is 0xFFFE, and -32768 is 0x8000. Anyone not seing the connection?

A word of caution: Some really strange systems use another way of coding negative values. They use the Most significant bit as a sign, and count upwards with the rest. (0x8001 = -1, 0x8002 = -2 )

The last size up is the dWord size. This one is 4Bytes or Double Word. I will leave for you to calculate the max values, assuming just positive or both positive/negative values. This one is usually known as a Long integer.

Now for a word of caution: Never just Assume the Integer and Long Integer variable sizes! This can vary from computer to computer, from language to language, and even from version to version! It's true!
At school, I worked with a language called ADA on Digital Vax computers. There the Integer was a dWord, and it lacked Long Integer. (The ADA standards specify that both must exist, but not the size) This of course caused some problems since I also worked on the same programs at home using my PC. And the ADA version I used there had the 'normal' types. (Integer as Word and Long Integer as dWord)

Natural: Ever seen a variable in a listing use this type and wondered wat it means? It's basically your normal integer, except that it's just Positive values. (0 - 65535)


<< >>
<<Maths>>
<<2 BCD, Endians, headaches...>>