Binary Code Analysis:Commonly used Binary Codes

Binary

WHAT IS A BINARY CODE?

A binary code represents text, computer processor instructions, or any other data using a two-symbol system. The two-symbol system used is often “0” and “1” from the binary number system. The binary code assigns a pattern of binary digits, also known as bits, to each character, instruction,

Binary code, is a  code used in digital computers based on a binary number system in which there are only two possible states, off and on, usually symbolized by 0 and 1. Whereas in a decimal system, which employs 10 digits, each digit position represents a power of 10 (100, 1,000, etc.), in a binary system each digit position represents a power of 2 (4, 8, 16, etc.). A binary code signal is a series of electrical pulses that represent numbers, characters, and operations to be performed. A device called a clock sends out regular pulses, and components such as transistors switch on (1) or off (0) to pass or block the pulses. In binary code, each decimal number (0–9) is represented by a set of four binary digits, or bits. The four fundamental arithmetic operations (addition, subtraction, multiplication, and division) can all be reduced to combinations of fundamental Boulen algebraic operations on binary numbers. (See the table below for how the decimal numbers from 0 to 10 are represented in binary.)

What is Binary Code Analysis ?

Binary code analysis, also referred to as binary analysis, is threat assessment and vulnerability testing at the binary code level. This analysis analyzes the raw binaries that compose a complete application, which is especially helpful when there isn’t access to the source code. Because a binary code analysis evaluates stripped binary code, software can be audited without vendor or coder cooperation. It can also be used to analyze third-party libraries, allowing a richer analysis and better visibility into how applications will interact with libraries. 

Binary code analysis has become more relevant as most of today’s cyber security threats move from network-level attacks to application layers. Applications can be very complex, written in various code languages drawn from multiple sources. Without being translated to a single raw binary code, it can be difficult to see or understand vulnerabilities at the code level. Over a website, applications with different codes or code sets must preserve security assessment deep into the program infrastructure. Analyzing for security threats at the binary code level (and preferably as part of the broader DevSecOps framework) helps ensure that web applications are not compromised before they go live.

Since binary code is fundamental, making sure to apply a static application security testing (SAST) approach as part of your overall security program is essential. SAST is a technological toolset that can analyze various static codes, like binary code, byte code, and application source code while they are in a non-running state—i.e., during the SDLC build phase.

TYPES OF BINARY CODES

Commonly used Binary Codes

Before going into the details of individual binary codes, let us quickly take a look at some of the commonly used Binary Codes. The following is the list:

  • 8421 Codes
  • 2421 Codes
  • 5211 Codes
  • Excess-3 Codes
  • Gray Codes

In the above list, the first three i.e. 8421, 2421 and 5211 are Weighted codes while the other two are non-weighted binary codes.

Weighted Binary Systems

The values assigned to consecutive places in the decimal system which is a place value system are 10⁴, 10³, 10², 10¹, 10⁰, 10⁻¹, 10⁻², 10⁻³… from left to right. It is easily can be understood that the weight of digit of the decimal system is ‘10’.

For example (3546.25)₁₀ = 3 x 10³ + 5 x 10² + 4 x 10¹ + 6 x 10⁰ + 2 x 10⁻¹ + 5 x 10⁻²

In the same way the values assigned to consecutive places in the binary system which is also a place value system, but called as weighted binary system are 2⁴, 2³, 2², 2¹, 2⁰, 2⁻¹, 2⁻², 2⁻³… from left to right. It is easily can be understood that the weight of digit of the binary system is ‘2’.

For example : (1110110)₂ = 1 x 2⁶+ 1 x  2⁵ + 1 x  2⁴ + 0 x  2³ + 1 x  2² + 1 x 2¹ + 0 x 2⁰

= 64 + 32 + 16 + 0 + 4 + 2 + 0 = (118)10

Binary Weights

Whenever any binary number appears, its decimal equivalent can be found easily as follows.

  • When there is 1 in a digit position, weight of that position should be added.
  • When there is 0 in a digit position, weight of that position should be disregarded.

For example binary number 1100 has a decimal equivalent of 8 + 4 + 0 + 0 = 12.

8421 Code or BCD Code

The decimal numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 can be expressed in Binary numbers as shown below. All these binary numbers again expressed in the last column by expanding into 4 bits. As per the weighted binary digits, the 4 Bit binary numbers can be expressed according to their place value from left to right as 8421 (2³ 2² 2¹ 2⁰ = 8421).

Decimal NumberBinary Number4 BIT Expression(8421)
000000
110001
2100010
3110011
41000100
51010101
61100110
71110111
810001000
910011001

As per the above expression all the decimal numbers written in the 4 Bit binary code in the form of 8421 and this is called as 8421 Code and also as Binary coded decimal BCD.

As this is a straight code, any Decimal number can be expressed easily because the weights of the positions are straight for easy conversion into this 8421 code.

There are other forms of codes which are not so popular but rather confusing. They are 2421 code, 5211 code, reflective code, sequential code, non- weighted coded, excess-3 code and Grey code. They are having their own importance for some of the exclusive applications and may be useful for some of the typical applications.

2421 Code

This code also a 4 bit application code where the binary weights carry 2, 4, 2, 1 from left to right.

Decimal NumberBinary Number2421 Code
000000
110001
2100010
3110011
41000100
51011011
61101100
71111101
810001110
910011111

5211 Code

This code is also a 4 bit application code where the binary weights carry 5, 4, 2, 1 from left to right.

Decimal NumberBinary Number5211 Code
000000
110001
2100011
3110101
41000111
51011000
61101010
71111100
810001110
910011111

Reflective Code

It can be observed that in the 2421 and 5211 codes, the code for decimal 9 is the complement of the code for decimal 0, the code for decimal 8 is the complement of the code for decimal 1, the code for decimal 7 is the complement of the code for decimal 2, the code for decimal 6 is the complement of the code for decimal 3, the code for decimal 5 is the complement of the code for decimal 4, these codes are called as reflexive codes. The same can be observed in the following table:

Decimal NumberDecimal Number2421 Code5211 Code
0000000000
1100010001
21000100011
31100110101
410001000111
510110111000
611011001010
711111011100
8100011101110
9100111111111

8421 code is not a reflective code.

Sequential Codes

Sequential codes are the codes in which 2 subsequent numbers in binary representation differ by only one digit. The 8421 and Excess-3 codes are examples of sequential codes. 2421 and 5211 codes do not come under sequential codes.

Decimal NumberBinary Number8421 CodeExcess-3
0000000011
1100010100
21000100101
31100110110
41001000111
510101011000
611001101001
711101111010
8100010001011
9100110011100

Non-Weighted Codes

Some of the codes will not follow the weights of the sequence binary numbers these are called as non-weighted codes. ASCII code and Grey code are some of the examples where they are coded for some special purpose applications and they do not follow the weighted binary number calculations.

Excess-3 Code

As mentioned above, some of the codes will not follow the binary weights, Excee-3 code is an example of it and it is an important 4 bit code. The excess – 3 code of a decimal number is achieved by adding the number 3 to the 8421 code.

For example to convert 15 to an excess-3 code, first 3 to be added to each digit as shown below.

Excess-3 Code Explanation

Excess -3 Code Examples
  1. Find the excess-3 code of (237.75)10
  2. Find the decimal number of excess-3 number 110010100011.01110101.

 Sol:

1) The excess-3 code for (237)10 is obtained by adding 3 to all the digits individually, that is 2, 3 an

d 7 will become 5, 6 and 10 respectively. These 5, 6 and 10 decimals have to be converted into binary form and the result is 010101101010.

The excess-3 code for (.75)10 is obtained by replacing 7 and 5 with 10 and 8 respectively by adding 3 to each digit. That is, the excess-3 code for (.75) ₁₀ is.10101000.

Combining the results of the integral and fractional parts, the excess-3 code for (237.75)₁₀ is 010101101010.10101000.

2) The excess-3 code is 110010100011.01110101

By separating 4 bits as group the equivalent excess-3 code is given as 1100 1010 0011.0111 0101.

Subtracting 0011 from each four-bit group, we obtain the new number as: 1001 0111 0000.0100 0010.

Therefore, the decimal equivalent is (970.42)10.

Gray Code

The gray code is the code where one bit will be differed to the preceding number. For example, decimal numbers 13 and 14 are represented by gray code numbers 1011 and 1001, these numbers differ only in single position that is the second position from the right. In the same way first position on the left changes for 7 and 8 which are 0100 and 1100 and this is also called Unit-distance code. The gray code has very special place in digital electronics.

Decimal NumberBinary CodeGray Code
000000000
100010001
200100011
300110010
401000110
501010111
601100101
701110100
810001100
910011101
1010101111
1110111110
1211001010
1311011011
1411101001
1511111000

ADVANTAGES OF BINARY CODES

Applications of Binary Number System

The binary number system is very useful in computer technology and computer programming languages also uses binary number system that is helpful in digital encoding. The binary number system can also be used in Boolean algebra.

Advantages and Disadvantages

The main advantage of using binary is that it is a base which is easily represented by electronic devices. The Binary Number System are also ease of use in coding, fewer computations and less computational errors.

The major disadvantage of binary number is difficult to read and write for humans because of large number of binary of a equivalent decimal number.

1’s and 2’s Complement of Binary (Base-2) Number

To get 1’s complement of a binary number, simply invert the given number. For example, 1’s complement of binary number 110010 is 001101.

2’s complement of binary number is 1’s complement of given number plus 1 to the least significant bit (LSB). For example 2’s complement of binary number 10010 is (01101) + 1 = 01110.

Drop your comment

0Shares

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *