RAM Diagram for beginers.

BlitzPlus Forums/BlitzPlus Programming/RAM Diagram for beginers.

Jono(Posted 2005) [#1]
ello all.

I've been keeping myself busying using all the information and that I've researched into making this diagram.



As you can see from it, it's a 24 byte RAM 7 bytes being taken up by a string of six bytes one byte being a NULL for end of string. What I would like to know is how a integer is stored, I remember in my old college course, my programming teacher telling me that an integer ranges from 0 to 32767. I unstand that using one byte I can have an integer from 0 to 255 but in programming that would be of little us in any program. So how do I make an integer number bigger using more bytes? Thank you all for helping me to get this far in understand memory storage.


Grey Alien(Posted 2005) [#2]
Your teacher should have said that an unsigned integer (always positive) is 0 to 65535 which is 2 bytes. A high byte and a low byte. If it is signed, the first bit is set to 1 to indicate that the number is negative so a signed integer can be from -32768 to 32767. These days integers are 32 bits and can be over 4 billion (unsigned) or 2 billion (signed).


Jono(Posted 2005) [#3]
Well now I understand that two bytes 256*256 equals 65536 as an unsigned integer, but how do you get -32767 to 32767 using a signed integer? Plus this new concept of signed and unsigned I'll need to look into, not sure what it really means. Which could be why I'm struggling to understand.


Floyd(Posted 2005) [#4]
That's actually -32768 to +32767.

Imagine you have a 3-digit odometer in your car. It can hold numbers 000 to 999. What if you wanted to treat some of these as negative?

Well, starting at 999 and driving 1 more will produce 000. In odometer arithmetic 999 + 1 = 0. So you could reasonably consider that 999 represents -1. Likewise 998 + 2 = 0 so 998 represents -2, etc.

In this way 000 to 499 may be considered positive and 500 to 999 are negative.

It's the same with binary. The 'lower half' are positive.


Jono(Posted 2005) [#5]


Thanks guys, I've learnt what unsigned integers are, just need to learn signed integers. Always with the learning. :D


Grey Alien(Posted 2005) [#6]
no wait, Floyd *was* explaining "signed" integers!


Jono(Posted 2005) [#7]
I know.


Grey Alien(Posted 2005) [#8]
oh ok :-)


Zenith(Posted 2005) [#9]
Usually you use the Highest bit to denote whether it is negative or positive.

But binary math either way is the same.
Mathworld has everything you need to know.
http://mathworld.wolfram.com/Binary.html


rdodson41(Posted 2005) [#10]
Yeah, %11111111 is -128 and %01111111 is +127. Thats a signed byte. Just think of the first 7 bits as holding the number and the last bit as telling wether its positive or negative.


Floyd(Posted 2005) [#11]
%11111111 is -1.

Adding 1 to it 'rolls over' to zero, as in my odometer analogy.


Zenith(Posted 2005) [#12]
No, not with 2nd's Compliment