0% found this document useful (0 votes)
33 views8 pages

Workshop 01: Number Systems & Memory

Here is the code with memory structure: #include <stdio.h> int main() { int a = 10; int b = 20; int c; c = a + b; printf("Sum is: %d\n", c); return 0; } Memory Structure: Stack: - Return Address - Frame Pointer - c - b - a Text (Code) Segment: - main() function code Data Segment: - No global/static variables Heap: - Not used in this program Therefore the overall memory layout is: Stack Text Segment Data
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

Workshop 01: Number Systems & Memory

Here is the code with memory structure: #include <stdio.h> int main() { int a = 10; int b = 20; int c; c = a + b; printf("Sum is: %d\n", c); return 0; } Memory Structure: Stack: - Return Address - Frame Pointer - c - b - a Text (Code) Segment: - main() function code Data Segment: - No global/static variables Heap: - Not used in this program Therefore the overall memory layout is: Stack Text Segment Data
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Subject: PRF192 - PFC

Workshop 01
Name: your_name
Student ID: your_student_ID

Objectives:
1. Reviewing for number systems.
2. Exploring memory of a C program.

Recommendations:
Part 1: Students do exercises using notebooks.
Part 2: Students develop programs, run them, write down their memory
structure to notebooks.
Part 1: Number systems:

Exercise 1 (2 marks): Convert decimal numbers to binary ones.

Decimal 4-bit Decimal 8-bit Decimal 16-bit Binary


Binary Binary

9 1001 7 0000 0111 255 0000 0000 1111 1111

7 0111 34 0010 0010 192 0000 0000 1100 0000

2 0010 125 0111 1101 188 0000 0000 1011 1100

15 1111 157 1001 1101 312 0000 0001 0011 1000

12 1100 162 1010 0010 517 0000 0010 0000 0101

11 1011 37 0010 0101 264 0000 0001 0000 1000

6 0110 66 0100 0010 543 0000 0010 0001 1111

5 0101 77 0100 1101 819 0000 0011 0011 0011

8 1000 88 0101 1000 1027 0000 0100 0000 0011

13 1101 99 0110 0011 2055 0000 1000 0000 0111

14 1110 109 0110 1101 63 0000 0000 0011 1111

Exercise 2 (2 marks): Convert decimal numbers to binary and


hexadecimal ones.
Decimal Binary Hexa. Decimal 16-bit Binary Hexadecimal

9 1001 09 255 0000 0000 1111 1111 00FF

127 0111 1111 7F 192 0000 0000 1100 0000 00C0

125 0111 1101 7D 188 0000 0000 1011 1100 00BC

157 1001 1101 9D 312 0000 0001 0011 1000 0138

162 1010 0010 A2 517 0000 0010 0000 0101 0205

37 0010 0101 25 264 0000 0001 0000 1000 0108

66 0100 0010 42 543 0000 0010 0001 1111 021F

77 0100 1101 4D 819 0000 0011 0011 0011 0333

88 0101 1000 58 1027 0000 0100 0000 0011 0403

99 0110 0011 63 2055 0000 1000 0000 0111 0807

109 0110 1101 6D 63 0000 0000 0011 1111 003F

Exercise 3 (2 marks): Compute.


(b: binary, q: octal, h: hexadecimal, d: decimal)
3 245 q + 247 q = ?q = ?b
3 245 q + 247 q = 3 514 q = 0111 0100 1100 b

1A7B h + 26FE7 h = ?h = ?b
1A7B h + 26FE7 h = 2 8A62 h = 0010 1000 1010 0110 0010 b

1101101101 b - 10110111 b = ?b
1101101101 b - 10110111 b = 0010 1011 0110 b

3654 q - 337 q = ?q = ?b
3654 q - 337 q = 3 315 q = 0110 1100 1101 b

3AB7 h - 1FA h = ?h = ?b
3AB7 h - 1FA h = 38BD h = 0011 1000 1011 1101 b

36A h - 576 q = ?h = ?b
576 q = 17E h
36A h - 576 q = 36A h - 17E h = 1EC h = 0001 1110 1100 b

64AE h - 1001101 b = ?q
1001101 b = 4D h
64AE h - 1001101 b = 64AE h - 4D h = 6461 h = 62 141 q

1 0110 1111 b
+ 1 0011 1011 b
1 1011 0001 b
1 1000 1101 b
= 0101 1110 1000 b

1011010 b * 1011 b

01011010 b
x 1011 b
01011010 b
01011010 b
00000000 b
01011010 b
= 01111011110 b = 0011 1101 1110 b

1101000 b + 2AB h + 345 q = ?h = ?q


1101000 b = 68 h
345 q = E5 h
1101000 b + 2AB h + 345 q = 68 h + 2AB h + E5 h = 3F8 h
3F8 h = 0011 1111 1000 b

3AF h / 1C h = ?b = ?d
3AF h = 943 d
1C h = 28 d
3AF h / 1C h = 943 d / 28 d = 33 d = 0010 0001 b

3AC h – 562 q = ?b = ?d
3AC h = 940 d
562 q = 370 d
3AC h – 562 q = 940 d - 370 d = 570 d = 0010 0011 1010 b

3FFA h / 327 q = ?b = ?d
3FFA h = 16378 d
327 q = 215 d
3FFA h / 327 q = 16378 d / 215 d = 76 d = 0100 1100 b

Exercise 4 (2 marks):

1. Show binary formats of 1-byte unsigned numbers: 251, 163, 117.


25110 = 1111 11012
16310 = 1010 00112
11710 = 0111 01012

2. Show binary formats of 2-byte unsigned numbers: 551, 160,


443.
55110 = 0000 0010 0010 01112
16010 = 0000 0000 1010 00002
44310 = 0000 0001 1011 10112

3. Show binary formats of 1-byte signed numbers: -51 , -163, -


117, 320.
-5110 = 1100 11012
-16310 = 0101 11012
-11710 = 1000 10112
32010 = overflow 8-bit, cannot storaged by binary formats of
1-byte.

4. Show the decimal values of 1-byte unsigned representations:


01100011 b , 10001111 b , 11001010 b , 01001100 b
0110 0011 b = 99 d
1000 1111 b = 143 d
1100 1010 b = 202 d
0100 1100 b = 76 d

Part 2: Explore memory structure of programs:

Sample
Complete the code of following program then draw it’s memory
structure. (2 marks)

Common questions

Powered by AI

The conversion of large hexadecimal numbers to binary highlights practical challenges such as the complexity of accurate transformations, the potential for errors in bit grouping, and the computational overhead involved in processing and verifying large datasets. These conversions are integral in various computing tasks like cryptography and data formatting, where precision is paramount. Managing such conversions manually underscores the importance of algorithmic methodologies in automating these processes efficiently, as seen in exercises involving conversions like those of 1A7B and 26FE7 .

Mastering arithmetic operations across different number systems enhances computational problem-solving abilities by fostering deep understanding of number bases and promoting algorithmic thinking. It involves critical skills like conversion accuracy, logical reasoning for different bases, and the ability to decompose problems into manageable parts, such as binary subtraction and hexadecimal overflows. This skill is highly applicable in fields like computer graphics, data processing, and algorithms where understanding binary and hexadecimal operations can lead to optimized solutions and efficient code. Exercises involving complex calculations, like those connecting octal, hexadecimal, and binary, provide practical insight and training .

Understanding the memory structure of a C program is crucial for debugging and optimization because it reveals how data are stored and accessed. This includes the stack, heap, and static memory areas, allowing programmers to identify memory leaks, efficiently manage memory allocation, and enhance performance by optimizing how memory is used. For example, knowing the allocation on the stack versus the heap can inform decisions to prevent stack overflow or excessive heap usage . These insights are important when writing efficient and error-free code as illustrated in exercises exploring memory .

Ensuring accuracy in manual calculations involves a systematic approach: first, understanding the base systems involved, then performing step-by-step conversion, and finally, validating the result through reverse conversion (e.g., back to decimal after binary conversion). Techniques such as consistent bit grouping for binary and systematic borrowing or carrying in extended operations reduce errors. Checking against known results, as shown in exercises like converting and summing across number systems, provides a form of validation. These steps require attention to detail and practice in order to minimize computational errors .

Converting between number systems such as octal, hexadecimal, and binary requires understanding the base of each system. The primary challenge is ensuring accuracy because each system represents values differently. For instance, each digit in hexadecimal represents four binary digits (a nibble) and each octal digit represents three binary digits, which necessitates careful grouping and conversion to avoid errors. Considerations include aligning the binary digits properly to their respective octal or hexadecimal groups to maintain value integrity, as demonstrated in exercises that involve such conversions .

Converting decimal numbers to different binary bit representations, such as 4-bit, 8-bit, and 16-bit, affects both precision and storage requirements. Fewer bits (e.g., 4-bit) can represent only a small range of numbers and may lead to a loss of precision due to limitations like overflow. In contrast, more bits (e.g., 16-bit) can represent a wider range of numbers and store larger values, thus requiring more memory but providing greater precision. For instance, a 4-bit binary can only represent numbers from 0 to 15, whereas an 8-bit binary extends this range from 0 to 255, allowing for more precise representations as shown in the exercises .

Practicing decimal to binary and hexadecimal conversion is fundamental for students as it solidifies their understanding of how computers interpret and process data, which is foundational in programming and computer science. In real-world scenarios, this skill is useful in network configuration, data encryption, and debugging binary data formats, where precise understanding of data representation is critical. Exercises that involve such calculations reinforce these essential skills by providing hands-on experience with number systems .

Exploring signed and unsigned binary number formats of 1-byte illustrates the limitations of storage systems, particularly in terms of range and representation. Unsigned 1-byte numbers can represent values from 0 to 255, while signed numbers can represent values from -128 to 127. This gap arises because one bit is used to denote the sign in signed representations, reducing the absolute value range. These exercises highlight how different format choices impact the maximum storable values and lead to phenomena like overflow, evident when trying to store a number like 320 in 1-byte signed format .

Understanding binary representation directly impacts the development of data structures by influencing decisions on data storage, manipulation, and retrieval efficiency. It helps developers determine the most suitable data structures for operations involving numerical data, such as using bitwise operations in sets, arrays, or hash functions. Recognizing binary patterns aids in optimizing space by choosing appropriate data types, leading to more efficient algorithms and memory management. Exercises that require conversion and evaluation of different number systems provide foundational insights into binary manipulation relevant to data structure optimization .

Showing binary formats for decimal numbers influences algorithm design by reinforcing an understanding of data representation and manipulation at a low level, critical for optimizing space and computational efficiency. Considerations include handling of edge cases, such as overflows and underflows, data size constraints in memory, and efficient bitwise operations utilization. By converting specific numbers, one learns to anticipate how these constraints impact algorithmic performance, thereby designing adaptable and efficient solutions. This approach aligns with a need to handle diverse data types and sizes accurately, as practiced through exercises converting decimal to binary formats .

You might also like