Menu Close

Binary Encoding

Posted in Digital Circuit

Binary encoding is a numerical encoding method consisting of two digits, 0 and 1. It is widely used in computer science and electronic engineering because the electronic components in a computer processor can only understand 0 and 1.

In binary encoding, each digit represents a weight, which is a power of 2. For example, a binary number 1101 represents:

1 × 2³ + 1 × 2² + 0 × 2¹ + 1 × 2⁰ = 8 + 4 + 0 + 1 = 13

Binary encoding can be used to represent various data types, such as numbers, characters, images, audio, video, etc. Inside a computer, all data is stored and processed in the form of binary encoding. For example, the binary encoding of a letter or symbol in a computer can be represented using standards such as ASCII code or Unicode code.

1. The Definition of Encoding

Encoding is defined as using binary numbers with a certain number of bits to represent decimal digits, letters, symbols and other information.

Through encoding, we can convert raw data into a format that can be processed and stored by computers. Common encoding methods include ASCII code and Unicode. In encoding, each binary digit represents a certain weight, usually a power of 2. Encoding can be used to represent various data types such as numbers, characters, images, audio, and video. In computers, all data is stored and processed in the form of binary encoding.

2. Source Code

Source code is an encoding formed by one or more 0s and 1s arranged in a specific order, such as 10, 01, 00, 11, etc.

When given specific rules, the source code can be converted into a well-defined encoding. For example, if the weight between the binary source code words is set to 2n, an unsigned binary number is formed. If positive and negative sign rules are added to the unsigned number, a signed number is formed. If a decimal point rule is added, a special binary fraction encoding is formed.

Related:   How to Convert Decimal to Hexadecimal?

3.One’s Complement

The concept of Two’s Complement in Chinese is very simple. It refers to a binary encoding method for integers in which each bit of the original code is flipped to obtain one’s Complement. Flipping a bit means changing 1 to 0 and 0 to 1.

For example, one’s complement code of “4’b1010” is “4’b0101”, and the one’s complement code of “8’b1000_1111” is “8’b0111_0000”.

4.Bias Code and Two’s Complement

The encoding of a binary number using the usual sequence of bits is called the natural code. For example, 0000 represents 0 and 1111 represents 15. Sometimes, a bias is added to the natural code to serve some specific purpose, which results in a biased code.

In some cases, a bias may also form due to direct current bias effect in circuit processing, which requires the study of how to eliminate the bias. The most commonly used biased code is the two’s complement, which is formed by subtracting 2N-1 (half of the whole number system) from the natural code. Here, N represents the number of bits in the binary system. For example, in a 4-bit binary system, the natural code is 0000-1111, and the bias is -2N-1=-23=-8, resulting in the two’s complement of a signed number. Please check following table for natural code and bias code of commonly used Integers .

table 1. natural code and bias code of commonly used Integers 

Natural Code Bias Code

(2’s Complement)

Decimal Number
Natural Code
Decimal Number
Bias Code
Two’s Complement
a Signed Number
0000 1000 0 -8
0001 1001 1 -7
0010 1010 2 -6
0011 1011 3 -5
0100 1100 4 -4
0101 1101 5 -3
0110 1110 6 -2
0111 1111 7 -1
1000 0000 8 0
1001 0001 9 1
1010 0010 10 2
1011 0011 11 3
1100 0100 12 4
1101 101 13 5
1110 0110 14 6
1111 0111 15 7

5. BCD code

BCD code, also known as binary coded decimal, uses a 4-bit binary number (b3b2b1b0) to represent the decimal digits 0 to 9. It is commonly referred to as the 8421 BCD code, where the weights of each digit position are 8, 4, 2, and 1, respectively.

Related:   Why Are Integers Stored in Memory in Two's Complement Form ?

The main reason for using BCD code is that binary or hexadecimal numbers are not intuitive when inputting, outputting, or displaying, such as (C8)16 or (11001000)2. We cannot immediately determine the size of the number. However, if the decimal number 200 is given, we can quickly respond to the size of the number.

It is important to note that not every 4-bit binary number corresponds to a BCD digit. There are six 4-bit binary numbers (1010), (1011), (1100), (1101), (1110), and (1111) that have no corresponding BCD code.

Table2.  BCD Code Table

Binary BCD Explain
0000 0 To express a decimal number using 4-bit binary code
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010,1011,1100,1101,1110,1111 No Defination

 

6.What is the Difference of BCD Code and Hexadecimal ?

Common points:

  • Both BCD code and hexadecimal number use 4-bit binary digits as their basic unit (bit).
  • They can represent the same numerical values from 0 to 9.

Differences:

  • BCD code has a radix of 10, while hexadecimal has a radix of 16.
  • BCD code only has the basic digits 0-9, while hexadecimal has 0-9 and the additional letters A-F.
  • BCD code has a weight of 10, while hexadecimal has a weight of 16.

7. ASCII encoding

To facilitate the use of computers, 7-bit binary numbers are encoded. The ASCII (American Standard Code for Information Interchange) code can easily handle numbers, letters, words, and articles. Later, it was extended to 256 Unicode and other codes. However, ASCII encoding is indeed the foundation of computer encoding.

Standard or lower ASCII characters and codes

Char Dec Binary Char Dec Binary Char Dec Binary
! 033 00100001 A 065 01000001 a 097 01100001
034 00100010 B 066 01000010 b 098 01100010
# 035 00100011 C 067 01000011 c 099 01100011
$ 036 00100100 D 068 01000100 d 100 01100100
% 037 00100101 E 069 01000101 e 101 01100101
& 038 00100110 F 070 01000110 f 102 01100110
039 00100111 G 071 01000111 g 103 01100111
( 040 00101000 H 072 01001000 h 104 01101000
) 041 00101001 I 073 01001001 i 105 01101001
* 042 00101010 J 074 01001010 j 106 01101010
+ 043 00101011 K 075 01001011 k 107 01101011
, 044 00101100 L 076 01001100 l 108 01101100
045 00101101 M 077 01001101 m 109 01101101
. 046 00101110 N 078 01001110 n 110 01101110
/ 047 00101111 O 079 01001111 o 111 01101111
0 048 00110000 P 080 01010000 p 112 01110000
1 049 00110001 Q 081 01010001 q 113 01110001
2 050 00110010 R 082 01010010 r 114 01110010
3 051 00110011 S 083 01010011 s 115 01110011
4 052 00110100 T 084 01010100 t 116 01110100
5 053 00110101 U 085 01010101 u 117 01110101
6 054 00110110 V 086 01010110 v 118 01110110
7 055 00110111 W 087 01010111 w 119 01110111
8 056 00111000 X 088 01011000 x 120 01111000
9 057 00111001 Y 089 01011001 y 121 01111001
: 058 00111010 Z 090 01011010 z 122 01111010
; 059 00111011 [ 091 01011011 { 123 01111011
< 060 00111100 \ 092 01011100 | 124 01111100
= 061 00111101 ] 093 01011101 } 125 01111101
> 062 00111110 ^ 094 01011110 ~ 126 01111110
? 063 00111111 _ 095 01011111 127 01111111
@ 064 01000000 ` 096 01100000
Related:   Learn Digital Circuit System From Beginning

Extended ASCII characters and codes

Extended ASCII uses eight instead of seven bits, which adds 128 additional characters.

This gives extended ASCII the ability for extra characters, such as special symbols, foreign language letters, and drawing characters as shown below.

Extended or Higher ASCII characters and codes

Higher ASCII chart

Leave a Reply