0% found this document useful (0 votes)
3 views10 pages

Computer Programming 1Part 1

The document explains various number systems including decimal, octal, hexadecimal, and binary, detailing their bases, digit representations, and conversion methods. It highlights the importance of understanding these systems for computer programming and data processing, emphasizing binary's role in computer operations. Additionally, it covers basic mathematical operations in binary and introduces the concept of algorithms in program design.

Uploaded by

micopasana14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Computer Programming 1Part 1

The document explains various number systems including decimal, octal, hexadecimal, and binary, detailing their bases, digit representations, and conversion methods. It highlights the importance of understanding these systems for computer programming and data processing, emphasizing binary's role in computer operations. Additionally, it covers basic mathematical operations in binary and introduces the concept of algorithms in program design.

Uploaded by

micopasana14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

ELCRIS M.

TIMBAL
Teacher

Learning Modules in IT Page 1 of 11


Decimal System
It is the number system that we commonly use for everyday life. It uses a base of 10 and
has only 10 digits from zero to 9. It is the first number system you learned while you were in
preschool. The decimal notation is described as the writing of numbers in base 10 numeral system,
for ten distinct values (1,2 ,3,4, 5, 6, 7, 8 and 9) to represent numbers. These digits are often used
with a decimal separator which indicates the start of a fractional part, and with one of the sign
symbols + (plus) or – (minus) to indicate sign.
The decimal system is a positional numeral system; it has positions for units, tens,
hundreds, and so on. The position of each digit conveys the multiplier (a power of ten) to be used in
that digit – each position has a value ten times that of the position to its right. For example, the
decimal number, 5468, consists of 8 in the units position, 6 in the tens position, 4 in the hundreds
position, and 5 in the thousands position, and its value van be written as:
(5x1000) + (4x100) + (6x10) + (8x1)
(5x103) + (4x102) + (6x101) + (8x100)
5000 + 400 + 60 + 8
5468
Octal System
The octal system or the base-8 is a number system that uses the digits 0 to 7 to
represent values. In the octal system, we add another column when counting beyond the 8 th digit or 7.
Consider the following example:
0,1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, …

Notice that after the number 7, we put 10. This is not the same as ten, but is read as “
one and zero” (1, 0) to represent the next value. This is the same for 20 which is not twenty but “two
and zero” (2, 0), and so on.
To illustrate the octal number system, observe the following table:

Decimal Octal
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 10 (1, 0)
9 11 (1, 1)
10 12 (1, 2)

Columns are used in the same way as the decimal system, as such the leftmost column
is used to represent the greatest value.
Hexadecimal System
The hexadecimal number system is a number system that uses sixteen digits as its base,
instead of 10 digits as in the decimal system. These sixteen digits are represented by 1, 2, 3, 4, 5, 6,
7, 8, 9, A, B, C, D, E, and F.
In the hexadecimal number system, when we reach 9, instead of adding another column
of the digit that starts with zero, we simply use a different digit represented by letter A.
Consider the following table as guide:

Decimal Octal Hexadecimal


Learning Modules in IT Page 2 of 11
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 10 (1, 0) 8
9 11 (1, 1) 9
10 12 (1, 2) A
11 13 (1, 3) B
12 14 (1, 4) C
13 15 (1, 5) D
14 16 (1, 6) E
15 17 (1, 7) F
16 20 (2, 0) 10
17 21 (2, 1) 11
18 22 (2, 2) 12
19 23 (2, 3) 13
20 24 (2, 4) 14
21 25 (2, 5) 15
22 26 (2, 6) 16
23 27 (2, 7) 17
24 30 (3, 0) 18
25 31 (3, 1) 19
26 32 (3, 2) 1A
27 33 (3, 3) 1B
28 34 (3, 4) 1C
29 35 (3, 5) 1D

Notice that the hexadecimal adds another column starting with zero only after exhausting
its sixteen digits. This repeats every time we count beyond its base of 16, just like how the decimal
system repeats and adds another column starting with zero after we exhaust its ten digits.
Binary System
The binary number system or the base-2 number system uses 0 and 1 to represent a
range of values. The binary number system follows the same principle as in the decimal, octal, and
hexadecimal number systems.
For example, with the decimal system, when we exhaust all the available digits (0 t0 9),
we simply add another column of 0 and write 1 on the left so we have 10, which represents ten.
The same principle works for the binary number system. When we exhaust all the
available digits (0 and 1), we simply add another column of 0 and write 1 on the left, so we have 10
(1, 0), which represents two. To illustrate this, study the following table on the next page.
The Binary Number System

Value Binary Number Explanation


0 Begin with zero…
• 1 …and then 1
•• 10 We have exhausted the available digits, so we add another column that
starts with zero, then write 1 on the left.
••• 11 Continue with another 1 on the right column. There are no more available
digits other than 1 and 0 since we have used them all.
•••• 100 Since we have exhausted all digits, we add another column that starts
with zero, then write 1 in the leftmost column.
••••• 101 Continue…
•••••• 110 …
Learning Modules in IT Page 3 of 11
••••••• 111 This is another turning point where we exhaust all our available digits
again.
•••••••• 1000 We simply add another column and write 1 one in the leftmost column
while changing the rest of the digits on the right to zero.
••••••••• 1001 And so on…

You have probably wondered why, of all number systems, it is the binary system that is
used for computers. In the first days of computer technology, the decimal system was used for its
operation. However, a mathematician named John von Neumann knew that a numbering scheme for
computers should be aligned with the physical characteristics of electronic circuitry, which only has
two states: on and off. By using the binary system, Neumann's design was able to simplify the ways
computers handle data.

Computers use binary codes to communicate to us in decimal format. A special program


is used to convert decimal to binary on the input process, and binary to decimal on the output
process.

In this lesson, we will learn how to perform number system conversion. This is important
for us to understand how computers process data and translate this data into different formats or
number base.

The Concept Of Base


When talking about number systems, we often hear the term base. This simply pertains
to the number of digits used in the numeral system. For example, a binary number system uses only
two digits which is zero and one that is why it is called base two number system. An Octal number
system uses only 8 digits composed of zero to 7 that is why it is called base 8 number system. The
decimal number system uses 10 digits composed of zero to 9 and it is called the base 10. The
hexadecimal system uses 16 digits from zero to 9, A to F. It is called the base 16.

Since we are working with four numbers systems that use only one numeral system (the
symbols 0 to 9) the represent their values, this can easily confuse readers when looking at numbers
and without knowing what kind of number system they represent.

In writing we distinguish different number systems from each other by indicating its base
using a subscript. Consider the following examples.

Example:
10002

In this example, we recognize that the set of digits are binary and not decimal because of
a subscript that indicates its base. Therefore, we know that the digits 1000 in the example do not
represent “one thousand” in decimal, but actually represent a value of 8 in binary, read as “one, zero,
zero, zero”. The same guide applies for octal, decimal, and hexadecimal numbers. Remember that
the subscript denotes the base of the number or its number system.

Converting Decimal System To Other Number Systems


We follow a very simple set of steps to convert decimal to binary octal or hexadecimal.
Step 1: Divide the decimal number to be converted by the value of the new base.

Step 2: Get the remainder from step one as the rightmost digit (least significant digit) of a new base
number.

Step 3: Divide the quotient of the previous by the new base.

Step 4: Record the remainder from step three as the next digit (to the left) of the new base number.

Repeat steps three and four, getting reminders from right to left until the quotient
becomes zero in Step 3.
Let us take a look at how these steps are applied in conversions from decimal to binary,
decimal to octal, and decimal to hexadecimal.

Learning Modules in IT Page 4 of 11


Converting Other Base Systems To Decimal System
We follow a very simple set of steps to convert decimal to binary, octal, or hexadecimal.
Step 1: We determine the positional value of each digit on their columns.

Step 2: Multiply the base digits by their base value, raised to the power of their positional value that
we get from step one.

Step 3: Get the some of the products from Step 2. The total is the equivalent value in decimal.

Converting Non-Decimal Number Systems


In programming, you are most likely to encounter non decimal number systems,
especially when defining values of certain elements, attributes, and properties in your program. For
this reason, we also need to know how to convert non decimal number systems into other non-
decimal number systems. For example, we can convert binary to octal and binary to hexadecimal.
These are very important skills in programming.

Today we hear a lot of buzz around the word “digital”. It has a lot to do with modern
computer technology. Surprisingly, only a few people know what it means when you ask them what
digital is, or what makes a computer digital.

A modern computer is an electronic device that uses digital signals. Digital signals
represent information with a sequence of 0s and 1s. Since digital signals are processed inside a
computer, what would they be the language of a computer is called machine language. For us to
understand how digital signals are processed, we have to learn binary number systems and the
mathematics behind it.

We already know the basics in addition, subtraction, multiplication, and division of


decimal numbers. Now, let us learn the different mathematical operations applied to binary numbers.

Binary Addition
Binary addition is done the same way as decimal addition, except that only 0s and 1s Are
used instead of the zero to 9. This makes a binary addition much simpler than decimal addition, as
we only need to remember the following rules:

Rule #1: 0 + 0 = 0
Rule #2: 0 + 1 = 1
Rule #3: 1 + 0 = 1
Rule #4: 1 + 1 = 10
Rule #5: 1 + 1 + 1 = 11

Binary Subtraction
Just like binary addition, binary subtraction has several rules when it comes to subtracting
its digits. Take note of the following basic rules for subtracting binary:

Rule #1: 0 - 0 = 0
Rule #2: 1 - 1 = 0
Rule #3: 1 - 0 = 1
Rule #4: 0 - 1 = 1

Binary Multiplication
Binary multiplication uses the same technique as decimal multiplication. In fact, binary
multiplication is much easier because each digit we multiply is either zero or one. All you have to
remember is that only 1 * 1 produces a product of 1, all the rest produces 0. Take a look at the basic
binary multiplication rules.

Rule #1: 0 * 0 = 0
Rule #2: 0 * 1 = 0
Rule #3: 1 * 0 = 0
Rule #4: 1 * 1 = 1

Binary Division

Learning Modules in IT Page 5 of 11


We can calculate binary division problems using the same technique as in the long
division in the decimal system. It will be helpful to review some of the basic terms for division.

When doing binary division, we need to remember some important rules:


1. When the remainder is greater than or equal to the divisor, write one in the quotient, multiply
the quotient and the divisor, then subtract the product from the dividend.
2. When the remainder is less than the divisor, write zero in the quotient an add another digit of
the dividend.
3. If all the digits of the dividend have been considered and there is still a remainder, mark radix
point in the dividend and append a zero. Remember that some fractions do not have an exact
representation in binary so not all division problems will terminate.

Let’s Expand!

Program design, sometimes called software design, is the process of developing how a
computer program should work or simply, designing how a program should respond to a set of
interrelated inputs. Program design is about writing a flow work that illustrates a sequence of options,
actions, and outputs. It is usually made in the form of a flow chart.

Algorithm
When designing a program, you must first outline the solution, and then develop that
solution into an algorithm. As a guide to outlining a solution, we usually answer the following
questions:
• What are the major steps involved?
• What are the major sub tasks involved?
• What are the major variables that affect decisions in the solution?

Once we have developed an initial outline, we can proceed to writing an algorithm for this
outline. An algorithm is a set of specific steps that describe the order and manner in which tasks shall
be performed to obtain a result or solve a problem.
Algorithms have five defining characteristics:
1. Algorithms are organized and follow a logical order. This means that we must write an
algorithm that has correct order or logic. A wrong order of operations may not work or may not
produce the desired result.
2. Algorithms have clear instructions. We must be very clear and simple on how we write our
algorithms. Our instructions must be very basic so that they no longer need to be simplified.
For example, if you have a list of letters that you want to arrange alphabetically, you
might write an instruction that says “sort these letters”. However, this is not clear to a computer
because it has no basic operation for sorting. When writing algorithms, we must stick to basic
operations, also known as primitive operations or simply primitives, which are the simplest form of
instructions that a computer can understand.
3. Algorithms have realistic or feasible instructions. When we write algorithms, remember that our
instruction must be feasible. Suppose you write an algorithm for cooking adobo, and your first
instruction says that you must gather all ingredients. You cannot execute this is if you have a
missing ingredient. In a computer, go to download an algorithm that demands the impossible
will not be executed. For example, mathematical operations that involve division by zero is
impossible and will not be executed by the computer.
4. Algorithms solve a problem or produce a result. The purpose of designing a program and
writing an algorithm is to solve a problem by producing a result. If the result satisfies the
problem, then the solution is good. If it does not, then the solution is not good.
5. Algorithms always end in a given amount of time. Our algorithms should have a finite number
of instructions. We must not write an algorithm that has no end. For example, if we want to
print all even integers, we might write an algorithm that appears like this:

1. Print the number 2


2. Print the number 4

Learning Modules in IT Page 6 of 11


3. Print the number 6
.
.
.
Notice that we used primitive operations (“print the number 2”), which is good. However,
we failed to put an end to the algorithm. In this form, the algorithm will run forever, violating the rule
that algorithms must have an end in a given amount of time.
Another problem-solving tool used in programming aside from algorithm is pseudocoding.
Methods Of Writing Algorithm
1. Stepping is a method where all instructions follow each other in a particular order to solve
the problem.
Example:
Problem: to compute the sum of three numbers
Algorithm: 1. Add the three numbers together
2.Write down the answer
Notice that the example list the algorithm in an ordered set of steps.

2. Looping consists of instructions that are repeated a number of times to get a resolution.
There are different types of loops: repeat until, while, and for.

Repeat until - this is a loop that carries out instructions repeatedly, and stops when given
the until command.
Example
Problem: wash the glass windowpane
Algorithm: 1. Repeat
2.Wash with warm soapy water
3. Until the window is clear

While - this is a loop where instructions are carried out while the condition is true;
otherwise, the loop stops indicated by the end while statement.

Example:
Problem: to ask for a number less than 5, then stop when such a number is given.
Algorithm: 1. While number given is less than 5
2. Ask for a number less than 5
3. End while

For - this is a loop that keeps on carrying out a command or commands, for a given
number of times. In this type of loop the number of times the instructions are repeated must be
declared. The instructions to be repeated are placed in between the four and end for commands.
Example:
Problem: to print the numbers from one to 10
Algorithm: 1. For n =1 to 10
2. Print n
3. End for

In For loop, the value of N starts at one and goes up to 10. Its value increases by one
each time it passes through the loop until it gets to 10. Since the value of N changes or varies, the
number is called a variable.
3. Choosing or selection method is used if the problem requires decision-making. The if-
then or if-then-else command for this conditional statement. The if command is followed
by an action or instruction to be executed. If the condition is satisfied, it is followed with
the then command. Is the condition is not satisfied, it is followed by else command.
Example:
Problem: to decide to go home
Algorithm: 1. If the time is 5:00 PM or later than 5:00 PM
2. Then go home

Learning Modules in IT Page 7 of 11


Example:
Problem: to determine a positive or negative number
Algorithm: 1. If the number is greater than or equal to 0
2. Then print positive number
3. Else print negative number

Pseudocode
Pseudo codes are short phrases that describe the instructions of an algorithm. These are
supposed to be human readable phrases instead of computer codes. Using pseudo codes allows us
to concentrate more on the logic and organization of our codes instead of the syntax of a
programming language. It saves time and resources.
Rules In Writing Pseudo Codes

• Write only one statement per line.


• Capitalize initial keyword.
• Indent the show hierarchy.
• End multiline structures.
• Keep statement language independent

Suppose you want to design a program that will obtain 2 numbers from the user. The
program shall calculate and print the total of those numbers. Your pseudocode will look something
like this:
1. Prompt the user to enter the first number.
2. Prompt the user to enter the second number.
3. Calculate the sum of the two numbers.
4. Display the result.

In writing an algorithm, analyze first the problem and decide what is needed to do to solve
the problem. Use the top-down design where the steps is simply written down in the correct order.
Creating Pseudo Codes
It was already discussed that pseudo codes are short phrases that define instructions for
algorithms. Before writing algorithms, the program should be designed in pseudo codes. Pseudo
codes follow three logic structures or control structures called sequence, selection, and iteration.
1. Sequence is a control structure that performs the actions from top to bottom or one after
another. The instructions are written in an order. It is the simplest form of program design.
Example
1. Read the first number
2. Read the second number
3. Compute the sum of the two numbers
4. Display the result

Here are the common action keywords used to indicate input, output, and process.
Input: read, obtain, get
Output: print, display, show
Process
Compute: compute, calculate, determine
Initialize: set, init
Add one: increment
2. The selection control structure is indicated by using if then else statement.
Syntax:
IF [condition] THEN
Learning Modules in IT Page 8 of 11
[statement 1]
ELSE
[statement 2]
ENDIF

If the condition yields true, statement 1 will be performed, or else, statement 2 will be done.
Example:

IF Age > = 18 THEN


Display “You are an Adult”

ELSE
Display “You are a Minor”

ENDIF

3. Iteration or loop structure performs the action repeatedly while the condition returns true.
Syntax:

WHILE [condition]
[Statement]

ENDWHILE

Example:

WHILE number > 10

Ask a number

ENDWHILE

The loop structure will ask the user a number until the given number is greater than 10. It
will stop asking if the number is lower than 10.

Let’s Ponder!

Answer each question on your answer sheet.

1. What do you think is the highest three-digit number you can have with the hexadecimal
system? Explain.
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
2. In an octal system, how will you represent a higher number if you exhaust all the available
digits from 0 to 7?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
3. Why do we need to learn number system conversion?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
4. What is the advantage in programming when we learn number system conversion?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
5. Why is it important to learn mathematical operations applied to binary numbers?

Learning Modules in IT Page 9 of 11


___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
6. Why is algorithm important in programming design?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
7. How do pseudocodes help us in programming?

A. Perform the following operations.


1. 101 + 11 =
2. 111 + 111 =
3. 1101 – 11 =
4. 10001 – 100 =
5. 101 x 10 =
B. Write an algorithm for each of the following problems.
1. To compute the area of a triangle
2. To determine if the grade is passed or failed
3. The display the remark “passed” if the grade is greater than or equal to 75 otherwise, display
“failed”
4. To ask for a number less than 20 then keep adding one until 20 is attained

Learning Modules in IT Page 10 of 11

You might also like