Professional Documents
Culture Documents
02 Number Systems and Control Structures
02 Number Systems and Control Structures
Steps:
Step 1 − Divide the decimal number to be converted by the value of the new base.
Step 2 − Get the remainder from Step 1 as the rightmost digit (least significant digit) of new base
number.
Step 3 − Divide the quotient of the previous divide by the new base.
Step 4 − Record the remainder from Step 3 as the next digit (to the left) of the new base
number.
Repeat Steps 3 and 4, getting remainders from right to left, until the quotient becomes zero in
Step 3.
The last remainder thus obtained will be the Most Significant Digit (MSD) of the new base
number.
Example:
Convert 2910 to binary
As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse order so that
the first remainder becomes the Least Significant Digit (LSD) and the last remainder becomes
the Most Significant Digit (MSD).
Programming Logic and Design
Steps:
Step 1 − Determine the column (positional) value of each digit (this depends on the position of
the digit and the base of the number system).
Step 2 − Multiply the obtained column values (in Step 1) by the digits in the corresponding
columns.
Step 3 − Sum the products calculated in Step 2. The total is the equivalent value in decimal.
Example:
Convert 111012 to Decimal
Steps:
Step 1 − Convert the original number to a decimal number (base 10).
Step 2 − Convert the decimal number so obtained to the new base number.
Example
Convert Octal Number − 258 to Binary
Page 2 of 6
02 Number Systems and Control Structures
Steps:
Step 1 − Divide the binary digits into groups of three (starting from the right).
Step 2 − Convert each group of three binary digits to one octal digit.
Example:
Convert binary number − 101012 to octal
Imaginary 0 to make it 3 bits
010 101
Step 2 101012 0 10 | 10 1
222120 222120
4 2 1 4 21
28 58
Step 3 101012 258
Steps:
Step 1 − Convert each octal digit to a 3 digit binary number (the octal digits may be treated as
decimal for this conversion).
Step 2 − Combine all the resulting binary groups (of 3 digits each) into a single binary number.
Example:
Convert octal number − 258 to binary
Page 3 of 6
Programming Logic and Design
Steps:
Step 1 − Divide the binary digits into groups of four (starting from the right).
Step 2 − Convert each group of four binary digits to one hexadecimal symbol.
Example:
Convert binary number – 101012 to hexadecimal
Steps:
Step 1 − Convert each hexadecimal digit to a 4 digit binary number (the hexadecimal digits may
be treated as decimal for this conversion).
Step 2 − Combine all the resulting binary groups (of 4 digits each) into a single binary number.
Example:
Convert Hexadecimal Number – 1516 to binary
Page 4 of 6
02 Number Systems and Control Structures
Example:
Baking a bread.
1. Add flour.
2. Add salt.
3. Add yeast.
4. Mix.
5. Add water.
6. Knead.
7. Let rise.
8. Bake.
Selection Structure
Also known as a conditional structure, a selection structure is a programming feature that
performs different processes based on whether a boolean condition is true or false. Selection
structures use relational operators to test conditions. [2]
Example:
Sorting a mail.
1. Get mail from mailbox.
2. Put mail on table.
3. Get piece of mail from table.
4. If (piece is personal) Then
Read it.
5. Else If (piece is magazine) Then
Put in magazine rack.
6. Else If (piece is bill) Then
Page 5 of 6
Programming Logic and Design
Pay it.
7. Else If (piece is junk mail) Then
Throw in waste basket.
Repetition Structure
Repetitive structures, also referred to as iterative structures, are groupings of code which are
designed to repeat a set of related statements. This repetition (or iteration) can repeat zero or
more times, until some control value or condition causes the repetition to cease. We use
iterative controls when we need to do the same task more than once, based upon some logical
condition. While the terms repetition and iteration are very descriptive words, the common
term to describe these control structures is loop. Loops consist of two logical parts; the
condition (i.e. the logic that evaluates the condition), and the loop body (i.e. where the code
integral to the loop is located). [3]
Example:
Washing the dishes.
1. Stack dishes by sink.
2. Fill sink with hot soapy water.
3. While (there are more dishes)
Get dish from counter.
Wash dish.
Put dish in drain rack.
End While
4. Wipe off counter.
5. Rinse out sink.
References
[1] V. Beal, "webopedia: sequence," QuinStreet Enterprise, 2018. [Online]. Available:
https://www.webopedia.com/TERM/S/sequence.html. [Accessed 21 June 2018].
[2] VirginiaTech, "Selection Structure," VirginiaTech, 2018. [Online]. Available: http://matlab.enge.vt.edu/selectionstructure.html.
[Accessed 21 June 2018].
[3] M. A. Thomas, "Introduction to Repetition Structures," 2007. [Online]. Available:
http://homepages.uc.edu/~thomam/Intro_OOP_Text/Loops.html. [Accessed 21 June 2018].
Page 6 of 6