Intro To Programming Module 1A

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

Republic of the Philippines

Mountain Province State Polytechnic College


Bontoc, Mountain Province

FUNDAMENTAL CONCEPTS OF COMPUTER


PROGRAMMING

Module 1 of 4 modules

Programming 1

Philip L. Balagtey
09514915726
[email protected]

Information Technology
1st Semester, School Year 2021-2022
INTRODUCTION
A computer is a machine that performs a variety of tasks according to specific
instructions. It is a data processing machine which accepts data via an input device
and its processor manipulates the data according to a program.
This module contains three lessons. The first lesson presents the basic
components of a computer, both hardware and software. The second lesson will give
us a brief overview of programming languages and the development life cycle of a
program. Finally, the third lesson describes the numbers system that computers use.
The number of hours allotted for this module shall be for 7 hours.

LEARNING OUTCOMES

At the end of the module, you should be able to:


1. identify accurately the parts of a computer system;
2. recognize different types of number systems as they relate to
computers; and,
3. apply problem solving the program development life cycle.

PRE-TEST

Choose the best answer for each question and write the letter of your
choice after the number.
1. What is an electronic device that manipulates data?_____________
a. Computer
b. Mouse
c. Printer
d. Typewriter

2. Which part is the "brain" of the computer? _____________


a. CPU
b. Monitor
c. RAM
d. ROM
3. What is the permanent memory built into your computer called?
_____________
a. CD-ROM
b. CPU
c. RAM
d. ROM

4. What is the binary equivalent of 9? _____________


a. 111
b. 1001
c. 1100
d. 1101

5. It is a clear and unambiguous specification of the steps needed to


solve a problem.? _____________
a. Algorithm

1
b. Code.
c. Flowchart
d. Pseudocode

6. Which of the following is an operating system you would be using on


the computer? _____________
a. Google Chrome
b. Microsoft Windows
c. Microsoft Word
d. Mozilla Firefox

7. It uses structured commands (mnemonics) as substitutions for


numbers allowing humans to read the code easier than looking at binary.
_____________
a. Assembly Language
b. High-Level Language
c. Low-Level Language
d. Machine Language

8. This step in Program Development Life Cycle involves breaking up the


problem into smaller and simpler subproblems. _____________
a. Coding
b. Debugging
c. Problem Analysis
d. Problem Definition

9. What is the decimal equivalent of 100101_____________


a. 33
b. 35
c. 37
d. 39

10. Programs that people use to get their work done. _____________
a. Application Software
b. Hardware
c. Operating Software
d. Screwdriver

2
LESSON 1: Components of a Computer System

Objectives:

At the end of the lesson, you should be able to:


1. describe the functions of different computer parts; and,
2. differentiate application software from system software.

LET’S ENGAGE

We cannot disregard the use of computer in our everyday lives. We are in


a world where people are connected with technology. Computer plays a vital
role that makes our lives easier. The computer as a whole is very important to
our lives but have you ever thought of the importance of its components?
We will start the lesson by checking your ability to name the main
components of the computer. Below is a picture of a computer, label each
component and identify if it is input or output device.

Source: ComputerHope.com

LET’S TALK ABOUT IT

A computer is a machine that performs a variety of tasks according to


specific instructions. It is a data processing machine which accepts data via an
input device and its processor manipulates the data according to a program.
The computer has two major components. The first one is the Hardware which
is the tangible part of the computer. It is composed of electronic and
mechanical parts. The second major component is the software which is the
intangible part of a computer. It consists of data and the computer programs.

3
Basic Components of a Computer
Hardware

Hardware is described as the physical component of a computer system.


Without any hardware, your computer would not exist and software could not
be used.

The Central Processing Unit


The processor is the “brain” of the computer. It contains millions of
extremely tiny electrical parts. The CPU's main function is to take input from
a peripheral (keyboard, mouse, printer, etc) or computer program, and
interpret what it needs. The CPU then either outputs information to your
monitor or performs the peripheral's requested task. Examples of processors
are Pentium, Athlon and SPARC.

Source: www.computerHope.com

Components of the CPU


In the CPU. There are two primary components.

ALU (Arithmetic Logic Unit) – performs mathematical, logical, and


decision operations.

CU (Control Unit) – directs all processors operations.

4
Memory
The memory is where data and instructions needed by the CPU to do its
appointed tasks can be found. It is divided into several storage locations which
have corresponding addresses. The CPU accesses the memory with the use of
these addresses.

Main memory
The main memory is very closely connected to the processor. It is used to
hold programs and data, that the processor is actively working with. It is not
used for long-term storage. It is sometimes called the RAM (Random Access
Memory).

The computer's main memory is considered as volatile storage. This


means that once the computer is turned off, all information residing in the
main memory is erased.

Main Memory

www.computerHope.com

Secondary Memory
The secondary memory is connected to main memory. It is used to hold
programs and data for long term use. Examples of secondary memory are hard
disks and flash drives.

Secondary memory is considered as non-volatile storage. This means


that information residing in secondary memory is not erased after the
computer is turned off.

Hard disk or Hard drive Flash Drive External Hard drive

Source: www.computerHope.com

Property Main Memory Secondary Memory


Speed Fast Slow
Price Expensive Cheap
Capacity Low High

5
Volatile Yes No

Input and Output Devices


Input and output devices allows a computer system to interact with the
outside world by moving data into and out of the system. Alternatively referred
as an I/O device.

Input Devices

Source: www.computerHope.com

Output Devices

Monitor Printer Projector

Software

www.computerHope.com

Software is a collection of instructions that enable the user to interact


with a computer. Computers would be useless without software. For example,
without internet browser you could not browse the internet. Without operating
system, you could not run the browser.

Computer Computer
Directs/
Software Hardware
Instructs

6
Some Types of Computer Software

System Software

System software is a software designed to operate the computer


hardware to provide basic functionality and to provide a platform for running
application software.

Refers to the operating system and all utility programs that manage
computer resources at a low level.

The BIOS (Basic Input/Output System) gets the computer system started
after you turn in on and manages the data flow between the operating system
and attached devices such as the hard disk, video adapter, keyboard, mouse
and printer.

Examples of System software are Windows, MacOS, Linux, Unix, Solaris


and etc. System software also includes system utilities, such as disk
defragmenter and System Restore.

Application Software

It is a program or group of programs designed for end-users. Programs


that people use to get their work done.

Examples:
Word Processor, Spreadsheet, Computer Games, Image Editor, etc.

Utility Software
Software utility is a computer system software intended to analyze, configure,
monitor, or help maintain a computer. Usually, a utility is smaller than a
standard program in size and may be included with an operating
system or installed separately.

Examples:
Backup Software, Compression utility, Disk partition software, file
manager, registry cleaners, screen savers, etc.

If you want to know more interesting facts about patterns or symmetries


in nature, visit the following:

Computer Hardware. https://www.youtube.com/watch?


v=vnBQ8QB2aRM&list=PLnLwAnYLqFhER_ReIQNIO3WsVK6vPBX9T

How Computer Work: Hardware and Software


https://www.youtube.com/watch?v=xnyFYiK2rSY

LESSON 2: Computer Programming Language

7
Objectives:

At the end of the lesson, you should be able to:


1. identify the basic structure and components of programming languages;
2. describe fundamental properties of programming language;
3. describe the activities involved in the program development life cycle;
and,
4. enumerate several tools that can be used by computer professionals
when designing a program.

LET’S ENGAGE

Picture yourself back in time working as a slave in Babylon. You are


feeling tired and hungry from carrying bricks. The scorching heat of the sun is
pricking your back. Looking around, you see many co-slave workers who are
also struggling to build the ultimate dream tower that will reach the gates of
heaven - the Tower of Babel.

Suddenly you hear a loud of thunder and in an instant, darkness


surrounds you. Within a few minutes, you hear people moaning crying and
wailing. You try speaking to some of you companions but you cannot
understand a word they are saying. Everyone else Is bewildered by what is
happening. You are stunned and then you begin to realize that you are all
speaking in different languages.
There is a sudden flash of light and then you find yourself brought back to the
present time. You begin to ask yourself, "What will happen to the people I have
left in that period? Will they able to accomplish our task of finishing the
highest tower in the world?"

This story sounds familiar because it can be found Genesis 11:1-10 of


the Holy Bible. Recalling the entire story will further tell the importance of
having a common language in order to accomplish certain tasks. The tower of
Babel was left unfinished because there was diversity in the people's goal and
ideas brought about by their language barrier.

The same is true with computers; you can never operate them without
using standard languages that will help you translate human readable
instructions to machine acceptable codes. Programming languages are
essential in the development of application software. In turn, these software
application enables you to use the computers for your daily needs.

8
LET’S TALK ABOUT IT

What is a programming language?


A program is a sequence of symbols that specifies a computation. A
programming language is a set of rules that specify which sequences of
symbols constitute a program, and what computation the program describes.
Programming languages allow people to give instructions to a computer with
commands that both the computer and the programmer can understand.
Different programming languages use different commands and different rules
for entering those commands.

A programming language is an artificial language designed to


communicate instructions to a machine, particularly a computer. Programming
languages can be used to create programs that control the behavior of a
machine and/or to express algorithms. Any programming language is
composed of a set of predefined words that are combined according to
predefined rules (syntax) to generate a computer program.

Source: www.techdotmatrix.com

Levels of Programming Languages


Presently, programming involves two following major level of
programming languages; Low level Language and High level language. The
binary machine language is usually defined as the lowest level, whereas the
highest level might be human language such as English.

Low Level Language


Low-level language is a programming language that deals with a
computer's hardware components and constraints. It has no or a minute level
of abstraction in reference to a computer and works to 5 manage a computer's
operational semantics. Low-level languages are designed to operate and handle
the entire hardware and instructions set architecture of a computer directly.

9
Source: www.technodotmatrix.com
Low-level programming language are divided into two categories:
Machine Language and Assembly Language.

Machine Language
Machine language is the sequence of bits (machine code) that directly
controls a processor, causing it to add, compare, move data from one place to
another, and so forth at appropriate times. The computer microprocessor can
process directly the machine codes without a previous transformation.
Specifying programs at this level of detail is an enormously tedious task.

Currently, programmers almost never write programs directly in machine


code, because it requires attention to numerous details which a high-level
language would handle automatically, and also requires memorizing or looking
up numerical codes for every instruction that is used.

Assembly Language
Assembly language uses structured commands (mnemonics) as
substitutions for numbers allowing humans to read the code easier than
looking at binary. Although easier to read than binary, assembly language is a
difficult language and is usually substituted for a higher language such as C.
Typically, one machine instruction is represented as one line of assembly
code. Assemblers produce object files which may be linked with other object
files or loaded on their own.

High Level Language


High Level languages have replaced machine and assembly language in
all areas of programming. Programming languages were designed to be high
level if it is independent of the underlying machine.

High-level languages (also known as problem-oriented languages) enable


a programmer to write programs that are more or less independent of a
particular type of computer. Such languages are considered high-level because
they are closer to human languages and farther from machine languages.

10
Source: www.technodotmatrix.com
High level languages are portable (machine independent) as it can be run
on different machines with little or no change.
Furthermore, the rules for programming in a particular high-level
language are much the same for all computers, so that a program written for
one computer can generally be run on many different computers with little or
no alteration. Thus, we see that a high-level language offers three significant
advantages over machine language: simplicity, uniformity and portability.

Higher-level languages provide a richer set of instructions and support,


making the programmer’s life even easier. The languages such as BASIC,
COBOL, FORTRAN, C, C++, JAVA and Visual Basic are popular examples of
high level languages. High level languages use translator programs such as
compiler and interpreter to convert it into a machine language program.

Computer languages were first composed of a series of steps to wire a


particular program; these morphed into a series of steps keyed into the
computer and then executed; later these languages acquired advanced features
such as logical branching and object orientation. Many programming
languages require computation to be specified in an imperative form (i.e., as a
sequence of operations to perform), while other languages utilize other forms of
program specification such as the declarative form (i.e., the desired result is
specified, not how to achieve it). Based on this programming paradigms
computer languages are classified into four main categories as follows.

Procedural languages: These languages use a programming approach, where a


developer writes code that describes in exacting detail the steps that the
computer must take to accomplish the goal.

Object oriented languages: These languages use a programming paradigm


that represents concepts as “objects” that have data fields and associated
procedures known as methods. Objects, which are instances of classes, are
used to interact with one another to design applications and computer
programs.

11
Logical Languages: The programming paradigm in these languages is based
on formal logic. A program written in a logic programming language is a set of
sentences in logical form, expressing facts and rules about some problem
domain.

Functional languages: This paradigm was explicitly created to support a pure


functional approach to problem solving. The programming approach in these
languages involves composing the problem as a set of functions to be executed.
These functions are predefined blocks of code intended to behave like
mathematical functions.

Language Translator

Source: http://www.vidyagyaan.com

Translator is meant to translate one language to another. So a translator


is mainly related to computer language. In case of a computer, its hardware
part only can operate when instructions are made of 0s and 1s, i.e., in machine
language.

There are different types of translators for different categories of


languages Software viz. assembler for assembly language, interpreter and
compiler for high-level language.

Source: www.differencebetween.info

Assembler
Programmers found it difficult to write or read programs in a machine
language. In their quest for a more convenient language they began to use a
mnemonic (symbol) for each machine instruction, which they would
subsequently translate into machine language. Such a pneumonic machine
language is now called an assembly language. Translator Programs known as
assemblers were written to automate the translation of assembly language into
machine language. As the assembly language is machine dependent, assembler

12
is also a machine dependent system program which must be supplied by the
computer manufacturer.

Hence, an assembler program translates source program in assembly


language into object program in machine language.

Interpreter
Source: www.codeforwin.org

An interpreter is a program which executes a source program usually on


a step by step, line by line, or unit by unit basis. In other wards an interpreter
will usually execute the smallest possible meaningful unit in the programming
language. The output of an interpreter is an actual answer, i.e. the result of
performing the actions designated in the program.

Source:www.codeforwin.org

Compiler
A compiler is simply a program which translates a source program
written in a particular programming language to an object program which is
capable of being run on a particular computer. The compiler is therefore both
language and machine dependent. The most important characteristic of a
complier is that its output is a program in some form or another and not an
answer of any kind. A complier must perform at least the following functions:
analysis of source code, retrieval of appropriate subroutines from a library,
storage allocation, and creation of actual machine code.

13
Source: www.greenteapea.com
Program Development Life Cycle
When we want to develop a program using any programming language,
we follow a sequence of steps. These steps are called phases in program
development. The program development life cycle is a set of steps or phases
that are used to develop a program in any programming language.

Problem Definition

Source: www.umich.edu

A programmer is usually given a task in the form of a problem. Before a


program can be designed to solve a particular problem, the problem must be
well and clearly defined first in terms of its input and output requirements. A
clearly defined problem is already half the solution. Computer programming
requires us to define the problem first before we even try to create a solution.
Let us now define our example problem: “Create a program that will determine
the number of times a name occurs in a list.”

Problem analysis
After the problem has been adequately defined, the simplest and yet the
most efficient and effective approach to solve the problem must be formulated.
Usually, this step involves breaking up the problem into smaller and simpler
sub problems. Example Problem: Determine the number of times a name
occurs in a list Input to the program: list of names, name to look for Output of
the program: the number of times the name occurs in a list

Algorithm Design and Representation

14
Once our problem is clearly defined, we can now set to finding a solution.
In computer programming, it is normally required to express our solution in a
step-by-step manner. An Algorithm is a clear and unambiguous specification of
the steps needed to solve a problem. It may be expressed in either Human
language (English, Tagalog), through a graphical representation like a flowchart
or through a pseudocode, which is a cross between human language and a
programming language. Now given the problem defined in the previous
sections, how do we express our general solution in such a way that it is
simple yet understandable? Expressing our solution through Human language:

1. Get the list of names


2. Get the name to look for, let's call this the keyname
3. Compare the keyname to each of the names in the list
4. If the keyname is the same with a name in the list, add 1 to the count
5. If all the names have been compared, output the result

Note: We will be discussing Algorithm and flowcharting in the succeeding


lessons.

Coding and Debugging


After constructing the algorithm, it is now possible to create the source
code. Using the algorithm as basis, the source code can now be written using
the chosen programming language.
Most of the time, after the programmer has written the program, the program
isn't 100% working right away. The programmer has to add some fixes to the
program in case of errors (also called bugs) that occurs in the program. This
process of is called debugging.

There are two types of errors that a programmer will encounter along the
way. The first one is compile-time error, and the other is runtime error.

Compile-Time Errors occur if there is a syntax error in the code. The


compiler will detect the error and the program won't even compile. At this

15
point, the programmer is unable to form an executable that a user can run
until the error is fixed.

Forgetting a semi-colon at the end of a statement or misspelling a certain


command, for example, is a compile-time error. It's something the compiler can
detect as an error.
Compilers aren't perfect and so can't catch all errors at compile time. This is
especially true for logic errors such as infinite loops. This type of error is called
runtime error.

For example, the actual syntax of the code looks okay. But when you
follow the code's logic, the same piece of code keeps executing over and over
again infinitely so that it loops. In such a case, compilers aren't really smart
enough to catch all of these types of errors at compile-time, and therefore, the
program compiles fine into an executable file. However, and unfortunately,
when the end-user runs the program, the program (or even their whole
computer) freezes up due to an infinite loop. Other types of run-time errors are
when an incorrect value is computed, the wrong thing happens, etc.

If you want to know more interesting facts about Programming Languages and
Program Development Life Cycle, visit the following:

Frame of Essence: How Do Computers Read Code?


https://www.youtube.com/watch?v=QXjU9qTsYCc

Machine Code and High Level Language Using Interpreters and Compilers.
https://www.youtube.com/watch?v=1OukpDfsuXE

Compiler and Interpreter: Compiled Language vs Interpreted Programming


Language. https://www.youtube.com/watch?v=I1f45REi3k4

LESSON 3: Number Systems and Conversion

Objectives:

At the end of the lesson, you should be able to:


1. describe various number system;
2. compare base 10 to a binary system; and,
3. convert numbers into different number systems.

LET’S ENGAGE
Computer and humans do not understand each other because it is does
not understand human language because it is arbitrary. But numbers are not
arbitrary, and that is the reason we prefer numbers to interact with computer
and machines. Hence, the number system was discovered. Number System is a

16
system through which we communicate and understand the machine. For
example, for a computer 0 is OFF and 1 is ON. In this lesson, we will discuss
different types of number systems, and their conversion rules.
Examine the table below.

•••
•••
• ••
• • •
••• ••
••• •


•••
• What do you spot about the dots on the card?
How many dots would the next card have if we continue on the left?
• •these
Use • cards to make numbers by turning some of them face down and

adding up the dots that are showing.

Example

•• 7

•• • •

6
••

••

When a binary number card is not showing, it is represented by ZERO.


When it is showing, it is represented by ONE. This is the Binary Number
System.

7
•• 17
• •
••
0 0 1 1 1

111 requires cards 4,2 and 1 the rest are facing down.
Using these cards, try to find the binary equivalent of these integers:
17 15 25 19 23

LET’S TALK ABOUT IT

Number System

In computers, Number System is defined as a writing system to represent


the numbers in different ways i.e. we are using different symbols and notations
to represent numbers. There are four ways we can represent the number. That
is, there are four types of Number System – Binary, Decimal, Octal,
Hexadecimal. Let us see each number system one by one.

Decimal Number
We normally represent numbers in their decimal form. Numbers in
decimal form are in base 10. This means that the only digits that appear are 0-
9. Here are examples of numbers written in decimal form:

126 base 10 normally just written 126


1110 normally just written 11

Binary Numbers

18
Numbers in binary form are in base 2. This means that the only legal
digits are 0 and 1. We need to write the subscript 2 to indicate that the number
is a binary number. Here are examples of numbers written in binary form:
11111102
10112

Octal Numbers
Numbers in octal form are in base 8. This means that the only legal
digits are 0-7. We need to write the subscript 8 to indicate that the number is
an octal number. Here are examples of numbers written in octal form:
1768
138
Hexadecimal
Hexadecimal Numbers in hexadecimal form are in base 16. This means
that the only legal digits are 0- 9 and the letters A-F (or a-f, lowercase or
uppercase does not matter). We need to write the subscript 16 to indicate that
the number is a hexadecimal number. Here are examples of numbers written
in hexadecimal form:
7E16
B16

Decimal to Binary
To convert a decimal number to binary, continuously divide the number
by 2 and get the remainder (which is either 0 or 1), and get that number as a
digit of the binary form of the number. Get the quotient and divide that
number again by 2 and repeat the whole process until the quotient reaches 0
or 1. We then get all the remainders starting from the last remainder, and the
result is the binary form of the number. NOTE: For the last digit which is
already less than the divisor (which is 2) just copy the value to the remainder
portion.

Quotien Remainder
t
126/2 63 0
63/2 31 1
Read this way

31/2 15 1

19
15/2 7 1
7/2 3 1
3/2 1 1
1/2 1
So, writing the remainders from the bottom up, we get the binary
number 11111102
Another Examples:

23/2111
11/251

Read this way


5/221
2/210
1/21

23 is equivalent to 1 0 1 1 1
34 / 2 17 0
17 / 2 8 1
8/2 4 0
4/2 2 0
2/2 1 0
34 is equivalent to 100010
1/ 2 1

Self-assessment: Convert the following decimal numbers to binary numbers.

55 109 51 120 98

Binary to Decimal
To convert a binary number to decimal, we multiply the binary digit to "2
raised to the position of the binary number". We then add all the products to
get the resulting decimal number.

For Example: 11111102 = ? 10


1111110

0 x 20 = 0

1 x 21 = 2

1 x 22 = 4

1 x 23 = 8

1 x 24 = 16

1 x 25 = 32

1 x 26 = 64

Total 126 20
110110 1110111 x 20 = 1
0 x 20 = 0
1 x 21 = 2 1 x 21= 2

1 x 22 = 4 0 x 22= 0

0 x 23 = 0 1 x 23= 8

1 x 24= 16 1 x 24= 16

1 x 25= 32 1 x 25= 32

Total = 54 Total = 59
Self-assessment: Convert the following binary numbers to decimal numbers.
11101
101101101
10001
101011
1101011

Decimal to Octal (or Hexadecimal)/Octal (or Hexadecimal) to Decimal


Converting decimal numbers to Octal or hexadecimal is basically the
same as converting decimal to binary. However, instead of having 2 as the
divisor, you replace it with 8(for octal) or 16 (for hexadecimal).
For Example (Octal): 126= ? 8
QUOTIENTREMAINDER
Read this way

126/8156

15/817

1/81

So, writing the remainders from the bottom up, we get the octal number
176 base 8

15010 to octal (base 8)


150 / 8 = 18 6
18 / 8 = 2 2
2 / 8 2
Answer:
12010 to octal (base 8) 226
120 / 8 = 15 0
15 / 8 = 1 7
1 / 8 1
Answer: 1708
Exercises: Convert the following decimal numbers to octal numbers

21
20
70
90
125
155
For Example (Hexadecimal):
12610 = ? 16

QUOTIENTREMAINDER

Read this way


126/16714 equal E to hex
digit

7/167

So, writing the remainders from the bottom up, we get the hexadecimal
number 7E16

12010 to hexadecimal (base 16)


120 / 16 = 7 8
7 / 16 = 7
Answer: 7816
15010 to hexadecimal (base 16)
150 / 16 = 9 6
9 / 16 = 9
Answer: 9616

Converting octal or hexadecimal numbers to decimal number is also the


same as converting binary numbers to decimal. To do that, we will just replace
the base number 2 with 8 for Octal and 16 for hexadecimal.
For Example (Octal): 1768 = ? 10

176

6 x 80 = 6

7 x 81 = 56

1 x 82 = 64

Total 126

2268 to decimal number


6 x 80 = 6
2 x 81 = 16
22
2 x 82 = 128
Answer: 15010
1708 to decimal number
0 x 80 = 0
For
7 xExample
81 = 56 (Octal): 7E16 = ? 10
1 x 82 = 64
Converting
Answer: 120hexadecimal
10
to binary number

7E

14 x 160 = 14

7 x 161 = 112

Total 126
Base on the table above E in hexadecimal is equivalent to 14 in decimal.
Let us try converting 7816 and 9616 to decimal number.
Binary 0to Octal / Octal to Binary
8 x 16 = 8
7 x 161 = 112
Answer: 120
6 x 160 = 6
9 x 161 = 144
Answer: 150

To convert from binary numbers to octal, we partition the binary number


into groups of 3 digits (from right to left), and pad it with zeros if the number of
digits is not divisible by 3. We then convert each partition into its
corresponding octal digit. The following is a table showing the binary
representation of each octal digit.
Octal digits and their corresponding binary representation.
Octal Digit Binary Representation
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

23
For Example:
1111110
0 0 1 1 1 1 1 1 0
1 7 6 Octal number
equivalent

Converting octal numbers to binary is just the opposite of what is given


above. Simply convert each octal digit into its binary representation (given the
table) and concatenate them. The result is the binary representation.
110110
1 1 0 1 1 0
6 6
Therefore, 110110 is equivalent 66 base 8.
Let us try another example.
111011
1 1 1 0 1 1
7 3
111011 is equivalent to 73 base 8.

Self-assessment: Convert the following binary numbers to octal number.


1011111
1000111
10011001
11100101
10100110

Binary to Hexadecimal / Hexadecimal to Binary


To convert from binary numbers to hexadecimal, we partition the binary
number into groups of 4 digits (from right to left), and pad it with zeros if the
number of digits is not divisible by 4. We then convert each partition into its
corresponding hexadecimal digit. The following is a table showing the binary
representation of each hexadecimal digit.

Hexadecimal Binary
Digit Representation
Hexadecim Binary
0 0000
al Digit Representatio
1 0001
n
2 0010
8 1000
3 0011
9 1001
4 0100
A 1010
5 0101
B 1011
6 0110
C 1100
7 0111
D 1101
E 1110
F 1111
Hexadecimal Digits and their corresponding binary representation

24
For Example:
11111102 = ? 16
1 1 1 1 1 1 0
7 E Hexadecimal Number Equivalent

Converting hexadecimal numbers to binary is just the opposite of what is


given above. Simply convert each hexadecimal digit into its binary
representation (given the table) and concatenate them. The result is the binary
representation.
Another examples;
110110 = ________

1 1 0 1 1 0 to hexadecimal number

1 1 0 1 1 0
3 6
Answer: 36

1 1 1 0 1 1 to hexadecimal number

1 1 1 0 1 1
3 B (11)
Answer: 3B

If you want to know more interesting facts about patterns or symmetries


in nature, visit the following:

Number System and the Base-ten System.


https://study.com/academy/lesson/number-systems-and-the-base-ten-
system.html

Digital Electronics: Introduction to Number System.


https://www.youtube.com/watch?v=crSGS1uBSNQ

25
REFERENCES

Atiwong Suchato. Learning computer programming using java with 101


samples.
Computer – Output Devices
https://www.tutorialspoint.com/computer_fundamentals/computer_out
put_devices.htm
C Program Language: Program Development Life Cycle
http://www.btechsmartclass.com/c_programming/C-Program-
Development-Life-Cycle.html
D.S. Malik (2012). Java Programming: Problem Analysis to Program Design 5th
Edition.
How do I install. https://java.com/en/download/help/download_options.xml
Java Made Easy. https://www.java-made-easy.com/java-
output.html#ixzz6Tsh9bQn8
Jason Killian (2012). Number Systems: An Introduction to Binary,
Hexadecimal, and more. Retrieved from
https://code.tutsplus.com/articles/number-systems-an-introduction-to-
binary-hexadecimal-and-more--active-10848

Programming Languages: Low Level, machine language, Assembly, High Level


Language (HLL); Algorithm and Flow chart: Concept and Uses
Programming Languages : Low Level, machine language, Assembly, High-level
Language (HLL); Algorithm and Flowchart: Concept and Uses. Retrieved
from
http://epgp.inflibnet.ac.in/epgpdata/uploads/epgp_content/library_and
_information_science/
information_communication_technology_for_libraries/
06._programming_languages/et/2061_et_6_ett.pdf
What is a computer language. Retrieved from
https://www.tutorialspoint.com/what-is-a-computer-language

26

You might also like