Chapter 2
- Binary to hexadecimal
0100 0101 0110 0111
=4567
1000 1001 1010 1011
=89ab
1111 1110 1101 1100
=fedc
0000 0010 0101 0010
=0252
- Hexadecimal to binary
83af
=1000 0011 1010 1111
9001
=1001 0000 0000 0001
aaaa
=1010 1010 1010 1010
5555
=0101 0101 0101 0101
- Number of bits
ffffffff
, 32 bits7fff58b7def0
, 48 bit1111
in binary is 4 bits1111
in hexadecimal is 16 bits
- Number of hexadecimal digits
- 8 bits, 2 hex digits
- 32 bits, 8 hex digits
- 64 bits, 16 hex digits
- 10 bits, 3 hex digits
- 20 bits, 5 hex digits
- 7 bits, 2 hex digits
- r = 10, n = 8, d7 = 2, d6 = 9, d5 = 4, d4 = 5, d3 = 8, d2 = 2, d1 = 5, d0 = 4 and r = 16, n = 8, d7 = 2, d6 = 9, d5 = 4, d4 = 5, d3 = 8, d2 = 2, d1 = 5, d0 = 4
- Binary to decimal
1010 1010
= 1700101 0101
= 851111 0000
= 2400000 1111
= 151000 0000
= 1280110 0011
= 990111 1011
= 1231111 1111
= 255
- Binary to decimal
1010 1011 1100 1101
= 439810001 0011 0011 0100
= 49161111 1110 1101 1100
= 652440000 0111 1101 1111
= 20151000 0000 0000 0000
= 327680000 0100 0000 0000
= 10240111 1011 1010 1010
= 316580011 0000 0011 1001
= 12345
- Hexadecimal to decimal
a000
= 40960ffff
= 655350400
= 10241111
= 43698888
= 349520190
= 400abcd
= 439815555
= 21845
- Unsigned decimal to hexadecimal
- 100 =
64
- 123 =
7b
- 10 =
0a
- 88 =
58
- 255 =
ff
- 16 =
10
- 32 =
20
- 128 =
80
- 100 =
- Unsigned decimal to hexadecimal
- 1024 =
0400
- 1000 =
03e8
- 32768 =
8000
- 32767 =
7fff
- 256 =
0100
- 65535 =
ffff
- 4660 =
1234
- 43981 =
abcd
- 1024 =
-
Since there are 12 values, we need 4 bits.
grade code grade code A 0x0
C 0x6
A- 0x1
C- 0x7
B+ 0x2
D+ 0x8
B 0x3
D 0x9
B- 0x4
D- 0xa
C+ 0x5
F 0xb
-
Lowercase
char code char code char code char code char code a 0x61
g 0x67
m 0x6d
s 0x73
y 0x79
b 0x62
h 0x68
n 0x6e
t 0x74
z 0x7a
c 0x63
i 0x69
o 0x6f
u 0x75
d 0x64
j 0x6a
p 0x70
v 0x76
e 0x65
k 0x6b
q 0x71
w 0x77
f 0x66
l 0x6c
r 0x72
x 0x78
-
Uppercase
char code char code char code char code char code A 0x41
G 0x47
M 0x4d
S 0x53
Y 0x59
B 0x42
H 0x48
N 0x4e
T 0x54
Z 0x5a
C 0x43
I 0x49
O 0x4f
U 0x55
D 0x44
J 0x4a
P 0x50
V 0x56
E 0x45
K 0x4b
Q 0x51
W 0x57
F 0x46
L 0x4c
R 0x52
X 0x58
-
Punctuation
char code char code char code char code char code spc 0x20
’ 0x27
. 0x2e
? 0x3f
` 0x60
! 0x21
( 0x28
/ 0x2f
@ 0x40
{ 0x7b
” 0x22
) 0x29
: 0x3a
[ 0x5b
} 0x7c
# 0x23
* 0x2a
; 0x3b
\ 0x5c
| 0x7d
$ 0x24
+ 0x2b
< 0x3c
] 0x5d
~ 0x7e
% 0x25
, 0x2c
= 0x3d
^ 0x5e
& 0x26
- 0x2d
> 0x3e
_ 0x5f
- dec2Hex
// Convert from decimal to hexadecimal #include <stdio.h> int main(void) { unsigned int value; printf("Decimal: "); scanf("%u", &value); printf("%u = 0x%02x\n", value, value); return 0; }
- hex2Dec.c
// Convert from hexadecimal to decimal #include <stdio.h> int main(void) { unsigned int value; printf("Hexadecimal: "); scanf("%x", &value); printf("0x%02x = %u\n", value, value); return 0; }
- The integer is -1, and the string is
0xffffffff
.