0% found this document useful (0 votes)
23 views4 pages

Ws 1

The document discusses a workshop on number systems and C program memory. It provides exercises on converting between decimal, binary, octal and hexadecimal numbers. It also has students develop simple programs and draw their memory structures.

Uploaded by

Trần Anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Ws 1

The document discusses a workshop on number systems and C program memory. It provides exercises on converting between decimal, binary, octal and hexadecimal numbers. It also has students develop simple programs and draw their memory structures.

Uploaded by

Trần Anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Subject: PRF192- PFC

Workshop 01
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 Hexadecim


al

9 1001 9 255 0000 0000 1111 1111 00FF


127 0111 1111 7F 192 0000 0000 0111 1111 C0
125 0111 1101 7D 188 0000 0000 1011 1100 BC

157 1001 1101 9D 312 0000 0001 0011 1000 138


162 1010 0010 A2 517 0000 0010 0000 0101 205
37 0010 0101 25 264 0000 0001 0000 1000 108
66 0100 0010 42 543 0000 0010 0001 1111 21F
77 0100 1101 4D 819 0000 0011 0011 0011 333
88 0101 1000 58 1027 0000 0100 0000 0011 403
99 0110 0011 63 2055 0000 1000 0000 0111 807

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

Exercise 3 (2 marks): Compute


(b: binary, q: octal, h: hexadecimal)

3245q + 247q = ?q = ?b 3514q = 11101001100b


1A7Bh + 26FE7h = ?h = ?b 28A62 = 0010 1000 1010 0110 0010b
1101101101b - 10110111b =?b 0010 1011 0110b
3654q – 337q =?q = ?b 3315q = 0110 1100 1101b
3AB7h – 1FAh = ?h = ?b 38BD = 0011 1000 1011 1101b
36Ah – 576q = ? h = ?b 4E8 = 0100 1110 1000
64AEh – 1001101b= ? q 62373q

101101111 b
+ 100111011 b
110110001 b
110001101 b
010111101000b

1011010 b* 1011b = 0011 1101 1110b


1101000b + 2AB h + 345 q = 1016 h = 1770 q
3AFh / 1Ch = 0010 0001 b = 33d
3ACh – 562q = 0010 0011 1010 b = 570 d
3FFA h / 327q = 0100 1100 b = 76 d

Exercise 4 (2 marks)

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


251: 1111 1011
163: 1010 0011
117: 0111 0101
2- Show binary formats of 2-byte unsigned numbers:551 , 160, 443
551: 0000 0010 0010 0111
160: 0000 0000 0010 0111
443: 0000 0001 1010 1011
3- Show binary formats of 1-byte signed numbers: -51 , -163, -117, 320
-51: 1100 1101
-163: 0101 1101
-117: 1000 1011
320: 0100 0000
4- Show the decimal values of 1-byte unsigned representations:01100011 b ,
10001111 b , 11001010 b , 01001100 b
01100011 b = 99
10001111 b = 143
11001010 b = 202
01001100 b = 76

Part 2: Explore memory structure of programs


Sample

c:22936 ‘A’
i:22936 1
l:2293 1000
f:22936 0.5
12.809
d:22936

Complete the code of following program then draw it’s memory structure
(2 marks)
#include <stdio.h>
int n;
double X;
char c1;
int main() {
int m;
short s;
long L;
float y;
printf("Code of main:%u\n", &main);
printf("Variable n, add:%u, memory size: %d\n", &n, sizeof(n));
printf("Variable X, add: %p, memory size: %d\n", &X, sizeof(X));
printf("Variable c1, add: %p, memory size: %d\n", &c1, sizeof(c1));
printf("Variable ma, add: %p, memory size: %d\n", &m, sizeof(m));
printf("Variable L, add: %p, memory size: %d\n", &L, sizeof(L));
printf("Variable y, add: %p, memory size: %d\n", &y, sizeof(y));
getchar();
return 0;
}

You might also like