You are on page 1of 32

Binary Codes

• The simplest form of


computer code or
programming data
represented by system of
digits consisting of string of
consecutive zeros and
ones.
• Binary code uses combinations
of these two numbers to
represent numbers, letters, or
other types of information.
• Is a base 2 number system
invented by Gottfried Leibniz
where numeric values are
represented by the different
combinations of 0 and 1, also
known as OFF or ON.
BITS and BYTES are major
components in writing binary.
Bit: a single 0 and 1 in a binary
number
- Smallest unit of data in a
computer
Bytes : eight bits put together
1 byte = 8 bits
• Binary system – base of 2 (0,1)
• Octal system – base of 8
(0,1,2,3,4,5,6,7)
• Decimal system – base of 10
( 0,1,2,3,4,5,6,7,8,9)
• Hexadecimal system- base of 16
(0,1,2,3,4,5,6,7,8,9,A,B,C,,D,E,F,)
• THREE TYPES OF BINARY CODING
1. ASCII – American Standard Code for
Information Interchange
2. EBCDIC – Extended Binary Coded
Decimal Interchange Code
3. UNICODE – Universal Code
HOW TO READ A BINARY CODE
The following chart illustrates the binary
number 01101000. In this example, we get the
total value by reading the chart from right to
left and adding each column’s value to that of
the previous column: (8+32+64) = 104. As you
can see, we do not count the bits with a 0
because they’re “turned off”.
Base of 2

Value 128 64 32 16 8 4 2 1

On/off 0 1 1 0 1 0 0 0
OFF ON ON OFF ON OFF OFF OFF
CONVERTING BINARY TO DECIMAL
Every digit in a binary number represents
a power of 2. For example if we were
working with the binary number
“00001101” we could convert it into
decimal with that chart

128 64 32 16 8 4 2 1

0 0 0 0 1 1 0 1

off off off off 8+ 4+ off 1


=13
CONVERTING DECIMAL TO BINARY
1. We would start with digits in “off” position
2. Next we find the largest power of two less than
the number and turn it “on” or put 1 there
3. Now, we would find the largest power of two
less than the number and repeat the process
Example:
Convert 23 to binary.
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 0
0 0 0 1 0 1 1 1
(23-16=7) (7-4=3) (3-2=1) (1-1=0)
QUIZ
Convert decimal Convert binary to
to binary. decimal
1. 100 6. 10111
2. 23 7. 101011
3. 95 8. 01001011
4. 258 9. 0000100
5. 33 10. 10001101
Coding theories
• Parity check
• Repetition code
• Modular arithmetic
Communication channel is the
physical medium in which
messages are being transmitted.
Examples of these are telephone
lines, internet cables, fiber-optic
lines and air. Storage of data is
another example which includes CD
rom, DVDs, USB port,etc
Noises may affect the
communications. Examples of
these are sunspots, lightning,
meteor showers and even human
errors. The tasks of CODING
THEORY is to detect or even
correct errors.
Encoding is transforming messages
into bits of message that is
suitable to the communication
channel.
Decoding is the opposite of
encoding.
Example: Consider the source
encoding of four directions;
North- 00 east – 10
South – 01 west – 11
What is the source encoded message
for:
North-south-east-west?
South-east-west-north?
Parity check is the process that ensures
accurate data transmission between codes
during communication. It is an encoding
scheme wherein a single bit is added to
the message as redundancy bit. Parity
checking is used not only in
communication but also to test memory
storage devices. Many PCs, for example,
perform parity check on memory every
time a byte of data is read.
Note: the goal in doing parity check
is to end up with an even parity .
1. Odd parity – a parity where the
number of 1s is odd.
2. Even parity – a parity where the
number of 1s is even
Example 1:Perform the channel
encoding by adding a redundancy bit
size of 3.
a. 00
b. 01
c. 10
d. 11
Repetition code is perform by taking
the k bits, then repeat it 2r + 1 times,
where r 1is a fixed integer.
Example 1: Suppose that the source
encoded message is 101. If r = 3, what
will be the message?
Example 2: Suppose that the source
encoded message is 01. If r = 2, what
will be the message?
Example 2: Suppose that the source
encoded message is 01. If r = 2,
what will be the message?
Example 3: What if the noise
affected the message in the given
example below and the message
decoded was 000110011111101?
Determine the correct source
encoded if r = 3.
MODULAR ARITHMETIC
• It is a system of arithmetic for
integers
• It is also known as “taking the
remainder”
• Modular arithmetic is about
using the division algorithm
• Integers – it include positive
and negative whole numbers, it
do not include fractions and
decimals.
• Modulo - is the operation of
finding the remainder when
you divide two numbers
Modulo n
Two integers a and b are congruent
modulo n, if (a-b) n is an integer.
If this is the case then,
a ≡ b modulo n.
• The number n is called modulus
• b is called the remainder
Example:
Determine whether the given
congruence is true or false
1. 29 ≡ 15 mod 7
2. 12 ≡ 3 mod 9
3. 12 ≡ 21 mod 9
4. 13 ≡ -6 mod 9
5. 15 ≡ 12 mod 3
Determine the value of the least
residue of m.
1. 29(mod 3)
2. 35(mod 4)
3. 25(mod 5)
4. (10 - 4) (mod 5)
5. (11 + 7) (mod 3)
CRYPTOGRAPHY
The word CRYPTOGRAPHY
originated from two greek words,
“krypto” which means hidden and
“graphene” which means writing. It is
the making or breaking of secret codes.
It uses two processes namely:
1. Encryption
2. decryption
1. Encryption – the process of
transforming plain text into
code form using a certain
algorithm.
Example:
Math is Fun (plain text)
PDWK LV IXQ (coded form)
2. Decryption – the process of
converting back the coded message into
plain text.
• Key – refers to the strings of
information that is used to reveal the
encrypted message into readable
form.
Methods of cryptography

- Shift cipher (ceasar cipher)


- Using modulo operator
Shift cipher method
Example
1. Using the key of shift 3 to the right,
encrypt the word,
“CRYPTOGRAPHY”

You might also like