Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Coding

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Binary Codes

Department of Mathematics and Natural Sciences

Math 031- Mathematics in the Modern World 1


An understanding of binary numbers, the binary system,
and how to convert between binary and decimal is
essential for anyone involved in computers, coding, and
networking.
At the end of this section, you are expected to:
1 Use coding schemes to encode and decode different
types of information for identification, privacy, and
security purposes.
2 Exemplify honesty and integrity when using codes
for security purposes.

Math 031- Mathematics in the Modern World 2


Definition
A binary code represents text, computer processor
intructions, or any other data using a two-symbol system.

Math 031- Mathematics in the Modern World 3


Conversion Binary to Decimal
In a binary system, each digit represents an increasing
power of 2, with the rightmost digit representing 20 , the
next 21 , then 22 , and so on. A binary number can be
converted into its equivalent decimal reprsentation by
summing up the power of 2 which each digit represents.
Example
Convert the binary number 10011010 into decimal.

Math 031- Mathematics in the Modern World 4


Conversion Binary to Decimal
The symbols 0’s and 1’s will serve as the coefficient/factors of
power of 2’s.
Start counting the power from the rightmost digit; for the
binary number 10011010, there are 8 digits, thus the highest
power of 2 is 7.
We have now the conversion:
100110102 = 1 × 27 + 0 × 26 + 0 × 25 + 1 × 24 + 1 × 23
+ 0 × 22 + 1 × 21 + 0 × 20
= 128 + 0 + 0 + 16 + 8 + 0 + 2 + 0
= 154

Math 031- Mathematics in the Modern World 5


Conversion Binary to Decimal
PRACTICE 1
Convert the given binary numbers into decimal.
1 1100111

2 100000001

3 11111101

Note: For answers please refer to the last part of this presentation.

Math 031- Mathematics in the Modern World 6


Conversion Decimal to Binary
An easy method of converting decimal to binary number
equivalents is write down the decimal number and to
continually divide by 2 to give a quotient and a
remainder of either 1 or 0 until the final quotient is 0.
Example
Convert the decimal 45 into binary equivalent.

Math 031- Mathematics in the Modern World 7


Conversion Decimal to Binary

45 ÷ 2 = 22 remainder = 1
22 ÷ 2 = 11 remainder = 0
11 ÷ 2 = 5 remainder = 1
5÷2=2 remainder = 1
2÷2=1 remainder = 0
1÷2=0 remainder = 1

Then right down the remainders from bottom to top.

Answer: 101101

Math 031- Mathematics in the Modern World 8


Conversion Decimal to Binary
PRACTICE 2
Convert the given binary numbers into decimal.
1 107

2 68

3 205

Note: For answers please refer to the last part of this presentation.

Math 031- Mathematics in the Modern World 9


Remark
Conversion from bnary to decimal and from decimal to binary can be
done using your scientific calculator. All you have to do is set the
mode of your calculator to ”Base N”.
Decimal to Binary
Press ”Dec” and input the number/given
Press ”Bin” and you will the binary equivalent of the given
decimal number
Binary to Decimal
Press ”Bin” and input the number/given
Press ”Dec” and you will the decimal equivalent of the given
binary number

Math 031- Mathematics in the Modern World 10


Integers in Computer

1 Bit - consists of 2 bits


2 Nibble or Quad - consists of 4 bits
3 Byte - consists of 8 bits
4 Word - consists of 16 bits

Math 031- Mathematics in the Modern World 11


ASCII Code
The most widely accepted code is called the American Standard
Code for Informaation Interchange (ASCII). The ASCII code
associates an integer value for each symbol in the character set,
such as letters, digits, punctuation marks, special characters, and
control characters. Computers convert text and other data into
binary by using an assigned ASCII value. Once the ASCII value is
known, that value can be converted into binary.
The following ASCII code of CAPITAL letters from A to Z
ASCII 65 66 67 68 69 70 71 72 73 74 75 76 77
Character A B C D E F G H I J K L M

ASCII 78 79 80 81 82 83 84 85 86 87 88 89 90
Character N O P Q R S T U V W X Y Z

Math 031- Mathematics in the Modern World 12


ASCII Code
Example
To print the word ”HELLO” what is the required binary digits that
the computer can understand?
Solution
Use the ASCII code for each letter. Convert each ASCII to
binary digits. It will be our convention to use Byte or 8 bits in
each letter.
The word ”HELLO” has four distinct letters ”H” ”E” ”L” and
”O”

Math 031- Mathematics in the Modern World 13


ASCII Code
Example
To print the word ”HELLO” what is the required binary digits that
the computer can understand?
Solution

LETTER H E L O
ASCII 72 69 76 79
Binary Equivalent 01001000 01000101 01001100 01001111
Note: A 0 is added to the left in order to have an 8-digit binary
equivalent for each letter and binary equivalent of ”L” must be
written twice.
Final Answer: 0100100001000101010011000100110001001111

Math 031- Mathematics in the Modern World 14


ASCII Code
Example
A certain binary digits 010000010100101001000001 are
detected after an input in the keyboard. What will be
the expected letters that will appear in the text editor?
Solution
Group the binary digits by 8 or in Bytes.
Convert each group to its corresponding decimal
equivalent to get the ASCII value.
Withe given ASCII values above write its
corresponding letters.

Math 031- Mathematics in the Modern World 15


ASCII Code
Example
A certain binary digits 01000001 01001010 01000001 are detected
after an input in the keyboard. What will be the expected letters
that will appear in the text editor?
Solution

Binary Equivalent 01000001 01001010 01000001


ASCII 65 74 65
LETTER A J A
Note: ASCII values that we have are for CAPITAL letters only.
Final Answer: AJA

Math 031- Mathematics in the Modern World 16


ASCII Code
PRACTICE 3
Translate the following binary codes into english words:
1 0101010001001000010000010100111001001011

2 010110010100111101010101

3 010000100101100101000101

Note: For answers please refer to the last part of this presentation.

Math 031- Mathematics in the Modern World 17


ASCII Code

ACTIVITY 3

Translate the following binary codes into english words:


1 0100101101000101010001010101 0000

2 01010011010000010100011001000101

3 0100101101001001 01000100 01010011

Math 031- Mathematics in the Modern World 18


Answers to Practice 1

1 103
2 257
3 253

Math 031- Mathematics in the Modern World 19


Answers to Practice 2

1 1101011
2 1000100
3 11001101

Math 031- Mathematics in the Modern World 20


Answers to Practice 3

1 THANK
2 YOU
3 BYE

Math 031- Mathematics in the Modern World 21

You might also like