Binary Representation of Numbers and Characters

In a computer, numbers are represented by numeric codes.

Representations of digits

Digits in base 10 (decimal): 0 1 2 3 4 5 6 7 8 9
 
Digits in base 16 (hex): 0 1 2 3 4 5 6 7 8 9 A B C D E F
 
Digits in base 8 (octal): 0 1 2 3 4 5 6 7
 
Digits in base 2 (binary): 0 1

Counting in different bases

What are the numbers after 9 in base 10?
10 11 12 ... 19 20 21 22 ... 99 100 101 ...
What are the numbers after F in base 16?
10 11 12... 19 1A 1B ... 1F 20 21 22 ... 99
9A 9B ... 9F A0 A1 ... A9 AA AB ... AF B0 ...
FF 100 101 ...
What are the numbers after 7 in base 8?
10 11 12 ... 17 20 21 22 ... 77 100 101 ...
What are the numbers after 1 in base 2?
10 11 100 101 110 111 1000 1001 1010
1011 1100 1101 1110 1111

Using bases other than 10

In base 10:
16498 = 1*104 + 6*103 + 4*102 + 9*101 + 8*100
In base 16:
16F98 = 1*164 + 6*163 + 15*162 + 9*161 + 8*160
So,  16F9816 = 9410410
In base 8:
16475 = 1*84 + 6*83 + 4*82 + 7*81 + 5*80
So,  164758 = 748510
In base 2:
11010 = 1*24 + 1*23 + 0*22 + 1*21 + 0*20
So,  110102 = 2610

What is the binary representation for 148?

Remember that:
20 = 1
21 = 2
22 = 4
23 = 8
24 = 16
25 = 32
26 = 64
27 = 128
28 = 256
29 = 512
210 = 1024

ASCII Code

The most common code used in computers is ASCII (American Standard Code for Information Interchange). It provides encoding of letters, digits, punctuation marks, and other special characters.

Subset of ASCII code:


        sp  !  :  #  $  %  &  T  (  )  *  +  ,  -
        32 33 34 35 36 37 38 39 40 41 42 43 44 45

         .  /  0  1  2  3  4  5  6  7  8  9  :  ;
        46 47 48 49 50 51 52 53 54 55 56 57 58 59

         <  =  >  ?  @  A  B  C  D  E  F  G  H  I
        60 61 62 63 64 65 66 67 68 69 70 71 72 73

         J  K  L  M  N  O  P  Q  R  S  T  U  V  W
        74 75 76 77 78 79 80 81 82 83 84 85 86 87

         X  Y  Z  [  \  ]  ^  _  `  a  b  c  d
        88 89 90 91 92 93 94 95 96 97 98 99 100

         e   f   g   h   i   j   k   l   m   n
        101 102 103 104 105 106 107 108 109 110

         o   p   q   r   s   t   u   v   w   x
        111 112 113 114 115 116 117 118 119 120

         y   z   {   |   }   ~
        121 122 123 124 125 126

What does this say?
72 101 108 108 111 32 67 108 97 115 115 33