Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Nguyen Khac Trang _ HE186034

Part 1
Exercise 1 (2 marks): Convert decimal numbers to binary ones
Decimal 4-bit Binary Decimal 8-bit Binary Decimal 16-bit Binary

9 1001 7 00000111 255 0000000011111111

7 0111 34 00100010 192 0000000011000000

2 0010 125 01111101 188 0000000010111100

15 1111 157 10011101 312 0000000100111000

12 1100 162 10100010 517 0000001000000101

11 1011 37 00100101 264 0000000100001000

6 0110 66 01000010 543 0000001000011111

5 0101 77 01001101 819 0000001100110011

8 1000 88 01011000 1027 0000010000000011

13 1101 99 01100011 2055 0000111111111111

14 1110 109 01101101 63 0000000000111111

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


hexadecimal ones

Decima Binary Hex Decimal 16-bit Binary Hexadecimal


l

9 1001 9 192 0000 0000 1100 0000 00C0

127 1111111 7F 188 0000 0000 1011 1100 00BC

125 1111101 7D 312 0000 0001 0011 1000 0138

157 10011101 9D 517 0000 0010 0000 0101 0205

162 10100010 A2 264 0000 0001 0001 1000 0108

37 100101 25 543 0000 0010 0000 1111 021F

66 1000010 42 819 0000 0011 0010 0011 0323

77 1001101 4D 1027 0000 0100 0000 0011 0403

88 1011000 58 2055 0000 0111 1111 1111 07FF

99 1100011 63 63 0000 0000 0011 1111 003F

109 1101101 6D 192 0000 0000 1100 0000 00C0

Exercise 3(2 marks): Compute


(b: binary, q: octal, h: hexadecimal)
3245q + 247q = 3492q = 0111001001010b
1A7Bh + 26FE7h = 28A62h = 1010001010110010b
1101101101b - 10110111b =101111100b
3654q – 337q =3317q=1100111101012b
3AB7h – 1FAh = 1BB1h=110111011001b
36Ah – 576q = 294q
64AEh – 1001101b= 63A3q
101101111 b
+ 100111011 b
110110001 b
110001101 b
= 1101111000 b

1011010 b* 1011b = 1110100110 b


1101000b + 2AB h + 345 q = 34F6h = 11001001q.
3AFh / 1Ch =22b=34d
3ACh – 562q = 26Fb = 623d
3FFA h / 327q = 374b=916d.

Exercise 4 (2 marks)
Show binary formats of 1-byte unsigned numbers: 251 , 163, 117
251: 11111011b
163: 10100011b
117: 01110101b
2- Show binary formats of 2-byte unsigned numbers: 551 , 160, 443
551: 00101001 00101111 b
160: 00000000 10100000 b
443:00000001 10110111 b
3- Show binary formats of 1-byte signed numbers: -51 , -163, -117, 320
−51: 11001101b
−163:10100001b
−117:10001011b
320 : Vượt quá vi phạm 1 byte của số nguyên
4-Show the decimal values of 1-byte unsigned representations: :
01100011 b , 10001111 b , 11001010 b , 01001100 b
01100011 b : 9
10001111 b : 143
11001010 b : 202
01001100 b : 76
Exercise 4

/* Variables Demo Operator &: address of */


// Nguyen Khac Trang - HE186034
#include <stdio.h>

int main() {
//KHAI BAO CAC BIEN
char c = 'C';
int i = 10;
long l = 100;
float f = 0.5f;
double d = 3.14;
// IN RA MAN HINH
printf("Variable c: at addr: %u, value: %c, size: %lu\n", &c, c,
sizeof(c));
printf("Variable i: at addr: %u, value: %d, size: %lu\n", &i, i, sizeof(i));
printf("Variable l: at addr: %u, value: %ld, size: %lu\n", &l, l, sizeof(l));
printf("Variable f: at addr: %u, value: %f, size: %lu\n",&f, f, sizeof(f));
printf("Variable d: at addr: %u, value: %f, size: %lu\n", &d, d,
sizeof(d));
getchar();
return 0;
}

You might also like