|
(Before you study this chapter, you may need to read chapter 18, Numbering systems.) Bits A "bit" is the smallest piece of data stored in your computer's memory. The value of a bit can be either 0 or 1. All data in your computer has a certain number of bits. Bytes A "byte" is 8 bits, and can have a value between 0 and 255 (or, in binary, between 0 and 11111111). A character, such as Q, takes up one byte of memory. This is because there are 256 different characters. (If you don't fully understand bits and bytes, don't worry about it.) How data is stored Data is stored in RAM at a certain memory address, as explained in chapter 3 (Variables). Each address takes up 1 byte of memory. Therefore, it can only have a value between 0 and 255. A memory address (on a 32-bit computer) can be somewhere between 0 and 4,294,967,295. In hexadecimal, this is between 0 and FFFFFFFF. Each memory address is divided into two parts: segments and offsets. See the figure below. ![]() Segments and offsets A memory address such as 12345678 (in hexadecimal) has a segment of 1234 and an offset of 5678. A segment can have a value between 0 and 65535 (or between 0 and FFFF). An offset can be within the same range. You can find out a memory address of a piece of data by multiplying its segment by 65536 (or 10000, in hexadecimal) and then adding its offset to the result. In QBasic, you can get a variable's segment by using VARSEG and its offset by using VARPTR.
offset = VARPTR(x) ' This prints the memory address of "x" (in decimal): PRINT (segment * 65536) + offset Feel free to distribute this tutorial, upload it to your website, link to it from your site, etc. http://www.geocities.com/progsharehouse/qbtutor Mirror: http://development.freeservers.com/qbtutor |