60 likes | 222 Views
Storing Other Integer Types in RAM. RAM Allocation. Data Type. Bits Required. Legal Values. unsigned int. 16 (2-bytes). 0 through 65,535. (No sign bit). 32 (4-bytes). long Or signed long. -2,147,483,648 through 2,147,483,647. 32 (4-bytes). 0 through 4,294,967,295. unsigned long.
E N D
Storing Other Integer Types in RAM RAM Allocation Data Type Bits Required Legal Values unsigned int 16 (2-bytes) 0 through 65,535 (No sign bit) 32 (4-bytes) long Or signed long -2,147,483,648 through 2,147,483,647 32 (4-bytes) 0through 4,294,967,295 unsigned long How would the data type long appear in RAM ???
Long Integers (c data type long) RAM Allocation Integers require 4 CONTIGUOUS bytes (32-bits) of storage Consider the c declaration: longl1 = ‘3’, l2; In Fact we are (once again): 1. Requesting 8-bytes (4 per variable) of RAM be reserved 2. Associating each variable name with a reserved location (LOCATIONSl1, and l2) 3. Initializing location l1 with ‘3’ ( = ASCII 51 = 1100112 = 0000000000000000000000001100112 on 32-bits)
Let’s again assume locations 9011 through 9017, and 9021 through 9076 Are available: RAM Allocation • Variable l1 is assigned address 9011 (through 9014) • Variable l2 is assigned address 9021 (through 9024) Why aren’t addresses 9015 through 9017 used??? Because we need 4 contiguous bytes of storage for longs: • If we were to try and store variable l2 at location 9015, we would need addresses 9016 through 9018 to be available also Looking at RAM, We might see:
9020 9017 9016 9022 9015 9014 9023 9013 9026 9012 9024 9011 9021 9025 9019 9018 11100001 00011001 00000000 00000000 00000000 00110011 00000100 01110011 01100110 00000000 111111111 00000000 10010010 00100010 01101111 00110110 longl1 = ‘3’, l2; l1 = 0000000000000000 0000000000110011 l2 is unassigned RAM Allocation • l1 stored at address 9011 (through 9014) • l2 stored at address 9021 (through 9024)
What ‘Garbage’ will we find at location l1 ??? At addresses 9021 through 9024, we find: RAM Allocation (On 32-bits) 11111111011011110010001010010010 Since the left-most bit = ‘1’ ( ==> the number is negative) we must compliment: (1’s Comp.) 0000000100100001101110101101101 + 1 (2’s Comp.) 0000000100100001101110101101110 = -(223 + 220 + 215 + 214 + 212 + 211 + 210 + 28 + 26 + 25 + 23 + 22 + 21) =-(8,388,608 + 1,048,576 + 32,768 + 16,384 + 4,096 + 2,048 + 1,024 + 256 + 64 + 32 + 8 + 4 + 2) = -9,493,870
This Concludes The Slides for this Section Choose an Option: Repeat Slides for this Section Go To Next Set of Slides For this Chapter Go To Slide Index For Chapter 3 Go To Slide Index For Chapter 4 Go To Slide Index For Textbook Go To Home Page