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

Chapter 5.

Codes

At the end of the chapter, you are expected to:

 Identify the different coding schemes


 Use coding schemes to encode and decode different types of information for identification, privacy,
and security purposes
 Exemplify honesty and integrity when using codes for security purposes

Introduction

Have you ever communicated with a friend in a


secret language that only the two of you could
understand, or played a game of charades? If so,
you've already had some experience with coding.

What is Code?

A code, at its most basic, is a set of rules that converts data from one representation of it into another. It is
like to speaking a foreign language, except that we communicate with symbols, numbers, or patterns rather
than words. There are several uses for this metamorphosis, from protecting secrets to facilitating effective
communication.

Representing Information through Hidden Symbols

Imagine a treasure map with cryptic symbols


marking the path to hidden riches. The symbols
themselves aren't the treasure, but they hold the
key to its location. Codes operate in a similar way,
concealing information within a system of symbols
that only those who understand the rules can
decipher. It's like dressing up information in a
disguise, allowing it to travel through different
channels without revealing its true identity.

Codes in Everyday Life - From Supermarkets to Cyberspace

Codes are all around us and are frequently at work in the background to keep the world running properly.
Common examples are:

1. Barcodes. Those black and white stripes on product packaging speak volumes to
scanners at checkout counters, revealing product details and prices in a
language machines can understand.

2. Passwords. They protect our online accounts and personal information by


transforming familiar words or phrases into secret combinations of
characters.
3. Encryption. It safeguards sensitive data like credit card numbers and private
messages by scrambling them into unreadable codes, ensuring only
authorized individuals can access their true meaning.

4. Traffic Lights. Their vibrant colors speak a universal language of road


safety, instructing drivers when to stop, go, or proceed with caution.

5. Morse Code. This historic code uses dots and dashes to convey messages through
sound or light, still used in aviation and maritime communications.

The Power of Codes

As we examine codes in more detail, we'll discover that they have the amazing ability to:

1. Secure Information. Protect sensitive data from unauthorized access or theft.

2. Efficient Communication. Transmit information quickly and accurately across different platforms.

3. Detect and Correct Errors. Ensure the integrity of data during transmission or storage.

4. Identify and Track Items. Assign unique codes to objects for organization and inventory management.

5. Explore New Frontiers. Codes play a crucial role in fields like space exploration, artificial intelligence, and
genetic research.

Codes are sets of instructions that are used to communicate with computers and other electronic devices.
They are the backbone of modern technology, from the apps on our phones to the software that powers
our fridges, air conditioners, cars, and more.

Coding, also known as programming, is the process of creating a set of instructions that computers can
execute. These instructions are written in programming languages such as Python, JavaScript, or C++,
among others. By using these languages, coders can communicate with computers to develop software,
design websites, build apps, and more.

Binary Code

Binary code represents information in a format that computers or other


electronic devices can interpret, and use. Binary code is the most basic form
of computer code, consisting of two numbers: 0 and 1. These numbers form
the basic layer of all computing systems and are the primary language of
digital technologies. Binary code uses combinations of these two numbers to
represent numbers, letters, or other types of information.
How Binary Code is used in Computers

Computers rely on binary code in many everyday digital operations. Central processing units (CPUs) use
binary to execute logical and arithmetic operations. When a computer sends information, it usually encodes
that information into binary format, decoding it back into its original format after transmission. Binary code
is the basis for all computing systems and operations, enabling devices to store, access, and manipulate all
types of information directed to and from the CPU or memory.

Conversion of decimal numbers to binary code and binary code to decimal numbers

To convert a decimal number to its binary equivalent, you can


follow these steps.

1. Divide the decimal number by 2 and note the remainder.


2. Divide the quotient (integer part of the division) by 2 and note the
remainder.
3. Repeat step 2 until the quotient is 0 or 1.
4. Write down the remainders in reverse order to get the binary
value of the given decimal number.

Example. Convert the decimal number 10 to binary.

1. Divide 10 by 2, which gives a quotient of 5 and a remainder of 0.


2. Divide 5 by 2, which gives a quotient of 2 and a remainder of 1.
3. Divide 2 by 2, which gives a quotient of 1 and a remainder of 0.
4. Divide 1 by 2, which gives a quotient of 0 and a remainder of 1.
5. Now, write down the remainders in reverse order: 1 0 1 0, which
is the binary equivalent of the decimal number 10.

To convert a binary number to its decimal equivalent, you can follow these steps.

1. Write down the binary number.


2. List the powers of two from right to left, starting from 0.
3. Write the digits of the binary number below their corresponding powers of two.
4. Multiply each binary digit by the corresponding power of two and sum the results to obtain the decimal
value.

Example. Convert the binary number 1010 to decimal.

1. The powers of two from right to left are 2^0, 2^1, 2^2, and 2^3.
2. Writing the binary number 1010 below the powers of two, we get:
1010
2^3 2^2 2^1 2^0
3. Multiplying each binary digit by the corresponding power of two and summing the results:
1(2^3) + 0(2^2) + 1(2^1) + 0(2^0) = 10

So, the binary number 1010 is equivalent to the decimal number 10.

Try: Convert the decimal number 13 to binary


Logic and Computer Addition

While we might envision computers as intelligent machines capable of complex calculations, their brilliance
stems from a foundation of simple, interconnected building blocks called logic gates. These gates act as
miniature decision-makers, processing binary inputs (0 or 1) and producing logical outputs based on specific
rules.

Logic Gates

Logic gates are electronic devices that perform binary operations, such as addition, based on the binary
digits 0 and 1. There are several types of logic gates, including the AND gate,,,, AND gate,,, OR gate, XOR
gate, and XNAND gate. These gates are used to process binary information in computers and other
electronic devices.

 AND Gate: Only outputs 1 if both inputs are 1. Imagine a security system requiring two keys to unlock.

 OR Gate: Outputs 1 if either or both inputs are 1. Think of a light turning on if either a switch or a
motion sensor is activated.

Computer Addition with Logic

Computers use logic gates to perform binary addition, which is the foundation of modern mathematics and
computing. In binary addition,,y, and the carry out value. When adding two binary numbers,, the exact
same procedure is followed as when adding two numbers in the decimal system (base 10).

When you add two numbers in the decimal system (base 10) you evaluate each column of
addition by taking into consideration any carry in value from the previous column and then
passing on to the next column any carry out value.
The exact same procedure is followed when you add two numbers in the binary system (base
2) as shown below.

Text Data

Computers can't inherently understand the nuances of human language. Text data, including
letters, symbols, and spaces, must be translated into a binary format for storage, processing, and
transmission.

Character Encoding Schemes

Character encoding schemes define a unique binary code for each character, ensuring consistent
representation across different systems.

1. ASCII Code. ASCII (American Standard Code for Information


Interchange) is a character encoding standard that
represents text in computers and communication
devices. It uses 7 bits to represent 128 English
characters, including letters, digits, and symbols, with
each character assigned a specific number in the
range 0 to 127. ASCII is widely used for representing
text in computers and telecom devices, making it
easier to transfer data from one device to another.

2. Unicode. Unicode is the universal character encoding standard


used to process, store, and facilitate the
interchange of text data in any language. It uses a
16-bit encoding scheme, allowing it to represent
over 65,000 different characters, which is
significantly more than the 128 characters
represented by ASCII. Unicode has become the
dominant character encoding standard for the
World Wide Web and modern communication,
addressing the limitations of ASCII and providing a
solution for representing characters in all human
languages

Encoding and Decoding

 Text Editors and Word Processors. Typically handle encoding and decoding automatically, ensuring
proper character display and editing.

 Web Browsers. Automatically detect and interpret character encoding based on web page metadata.
Errors and Error Correction

While the digital world strives for precision, errors inevitably creep into data transmission and storage.
These glitches can arise from various sources.

1. Physical Interference. Electrical noise, signal degradation, and hardware malfunctions can corrupt data
bits.

2. Software Bugs. Programming errors or faulty algorithms can introduce errors during data processing.

3. Human Mistakes. Typos, accidental file deletions, or incorrect data entry can also lead to errors.

Types of Errors

1. Single-Bit Errors. A single bit within a data unit flips from its original value (0 to 1 or vice versa).

2. Burst Errors. Multiple adjacent bits are affected simultaneously, often due to physical interference or
transmission bursts.

Consequences of Errors

 Distorted Images [Image showing a corrupted image due to data errors]

 Misspelled Text[Image showing text with errors due to data corruption]

 Incorrect Calculations. Flawed financial transactions, misleading scientific results, or faulty software
operations.

Error Detection

1. Parity Checks. A simple method that adds an extra bit (parity bit) to a data unit to ensure an even or
odd number of 1s.

Parity Check Example

2. Checksums. A mathematical calculation based on a data block's content, used to verify its integrity upon
transmission or storage.

3. Cyclic Redundancy Checks (CRCs). More sophisticated error-detection mechanism using polynomial
division to generate a unique checksum.
References:

[1] What Is Binary Code? https://www.coursera.org/articles/binary-code;


https://www.britannica.com/technology/data-compression

[2] Binary Addition with Logic Gates. https://bjc.edc.org/bjc-r/cur/programming/6-computers/optional-


projects/2-adder.html

You might also like