ram allocation
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
Page 1
Data Structures in C for Non-Computer Science Majors
Kirs and Pflughoeft
RAM Allocation
Storing Other Integer Types in RAMStoring Other Integer Types in RAM
Data Type
unsigned int
Bits Required
16 (2-bytes)
Legal Values
0 through 65,535(No sign bit)
longOr signed long
32 (4-bytes) -2,147,483,648 through 2,147,483,647
unsigned long 32 (4-bytes) 0 through 4,294,967,295
How would the data type How would the data type longlong appear in RAM ??? appear in RAM ???
Page 2
Data Structures in C for Non-Computer Science Majors
Kirs and Pflughoeft
RAM Allocation
Long Integers (c data type Long Integers (c data type longlong))Integers require 4 CONTIGUOUS bytes (32-bits) of storage
Consider the c declaration:
longlong l1 = ‘3’, l2;
In Fact we are (once again):
1. Requesting 8-bytes (4 per variable) of RAM be reserved2. Associating each variable name with a reserved location
(LOCATIONS l1, and l2)3. Initializing location l1 with ‘3’
( = ASCII 51 = 1100112 = 0000000000000000000000001100112 on 32-bits)
Page 3
Data Structures in C for Non-Computer Science Majors
Kirs and Pflughoeft
RAM Allocation
Let’s again assume locations 9011 through 9017, and 9021 through 9076 Are available:
• Variable l1 is assigned address 9011 (through 9014)• Variable l2 is assigned address 9021 (through 9024)
Why aren’t addresses Why aren’t addresses 90159015 through through 90179017 used??? used???
Because we need 4 contiguouscontiguous 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:
Page 4
Data Structures in C for Non-Computer Science Majors
Kirs and Pflughoeft
RAM Allocation
longlong l1 = ‘3’, l2; l1 = 0000000000000000 0000000000110011 l2 is unassigned
• l1 stored at address 9011 (through 9014)• l2 stored at address 9021 (through 9024)
9011
000000009012
000000009013
000000009014
001100119015
000001009016
111000019017
000000009018
011100119019
000110019020
011001109021
1111111119022
011011119023
001000109024
100100109025
000000009026
00110110
Page 5
Data Structures in C for Non-Computer Science Majors
Kirs and Pflughoeft
RAM Allocation
What ‘Garbage’ will we find at location What ‘Garbage’ will we find at location l1l1 ??? ???At addresses 9021 through 9024, we find:
11111111011011110010001010010010 (On 32-bits)
Since the left-most bit = ‘1’ ( ==> the number is negative) we must compliment:
0000000100100001101110101101101+ 1
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,8709,493,870
(1’s Comp.)
(2’s Comp.)
Page 6
Data Structures in C for Non-Computer Science Majors
Kirs and Pflughoeft
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
This Concludes The Slides for this Section
Choose an Option: