0% found this document useful (0 votes)
24 views

Lecture BinaryNumberSystem

Here are the key points about representing negative values in binary number systems: - Signed Magnitude (SM): Use the most significant bit as the sign bit, where 0 represents positive and 1 represents negative. The value is interpreted as is. For example: - 0110_01 = Positive 29 - 1110_01 = Negative 29 - One's Complement (OC): Flip all the bits to represent negative numbers. For example, in a 4-bit system: - 0101 = Positive 5 - 1010 = Negative 5 - Two's Complement (TC): Flip all the bits and add 1 to the result. This avoids having two representations for zero (all 0s and all 1s).

Uploaded by

evelynsevilla074
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lecture BinaryNumberSystem

Here are the key points about representing negative values in binary number systems: - Signed Magnitude (SM): Use the most significant bit as the sign bit, where 0 represents positive and 1 represents negative. The value is interpreted as is. For example: - 0110_01 = Positive 29 - 1110_01 = Negative 29 - One's Complement (OC): Flip all the bits to represent negative numbers. For example, in a 4-bit system: - 0101 = Positive 5 - 1010 = Negative 5 - Two's Complement (TC): Flip all the bits and add 1 to the result. This avoids having two representations for zero (all 0s and all 1s).

Uploaded by

evelynsevilla074
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 29

Objectives

 Know the different number systems and be able to convert one to


another
 Do simple arithmetic with the different number systems
 Explain in detail the significance of the binary number system in
computer systems
 Solve problems using flowcharts and pseudo-codes
 Make syntactically correct program codes
 Develop a program for a given problem
Outline
 Brief Introduction to Computers
 Number Systems
 Binary
 Octal
 Hexadecimal
 Problem Solving
 Flowcharts
 Pseudo-codes
 Introduction to C++
 C++ Control Structures
 Selective
 Repetitive
Topic Outline

 Arrays and Strings


 Modularity using Functions
 Pointers and References
 Structures
References
 C++ How to Program. Deitel, H. M., Deitel, P. J.
Prentice-Hall Inc., (2001).
 C How to Program. Deitel, H. M., Deitel, P. J.
Prentice-Hall Inc., (2000).
 A First Book of Visual C++. Bronson, G. J.
Brooks/Cole Publishing Company, (2000).
Requirements
 Class Standing: 50% Lecture + 30 % Laboratory + 20%
IT News/Requirements (Music Video or Video
Documentation)
 Lecture
 Long Exams – 60%

 Recitation – 15%

 Short Quizzes – 20%

 Assignment – 5%

 Laboratory
 Machine Problems – 40%

 Take Home Machine Problems – 20%

 Hands-on Long Exams – 40%

 Final Grade: 2/3 CS + 1/3 Periodical Test


Exemption Policy

 Exemption grade for the finals is 80%


based solely on the class standing.
The student will be given an exemption
only when she/he passes both the
lecture and lab grades.
Grading of Machine Problems

 10 – perfectly running with documentation


 7 – fails in some minor test cases or no documentation
 4 – fails on most test cases
 1 – does not solve the problem or no relation to the
problem at all
 0 – no submission, contains syntax errors, wrong file
submitted
Class Policies
 You are allowed a maximum of 5 unexcused absences
 Tardiness shall not be tolerated (3 sessions late equivalent to 1
absence). If you are late for more than 15 minutes you shall be
considered absent.
 No special assignments, quizzes and programming work shall be
given to any student even if with valid excuse.
 Special long/final exams shall be granted to students with valid
excuse only.
 Valid excuse defined: hospitalization, death of an immediate family
member.
 The special exams will be granted upon presentation of proof
(certificate) duly authenticated by the Guidance Office).
 CHEATING OF ANY FORM SHALL NOT BE TOLERATED.
 Assignment – automatic score of ZERO

 Exams (short/long/finals) – automatic grade of 68.

 NO ID means 1 absence.
ANY QUESTIONS?
The Binary Number
System
What is binary?
 First invented by Gottfried Leibniz in the 17th
century, the binary number system became widely
used once computers required a way to represent
numbers using mechanical switches.
 Binary describes a numbering scheme in which
there are only two possible values for each digit --
0 or 1 -- and it is the basis for all binary code used
in computing systems.

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
[Cont’n…]
 These systems use this code to understand
operational instructions and user input and to
present a relevant output to the user.
 in computing systems, a binary digit, or bit, is
the smallest unit of data.
 A digital one or zero is simply an electrical signal
that's either turned on or turned off inside of a
hardware device like a CPU,RAM which can hold
and calculate many millions of binary numbers.

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
What is it?
 A numeral system that represents numeric values using two
symbols, 0 and 1.
 Base 2 positional notation with a radix of 2.
 Powers of 2
 20, 21, 22, 23, 24, 25, 26, …

 1, 2, 4, 8, 16, 32, 64, …

 Example: 11012 = 1x20+0x21+1x22+1x23


=1+0+4+8
= 13

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Exercise:
 Try converting the following binary numbers to their
decimal equivalent
 11100110

 10101101

 11111111

 10000001

 11101111

Note: If all the bits are 1, then its decimal equivalent is 2n


– 1 where n is the number of 1s.

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Note:
 Computers are machines and they can only
understand instructions if these are given to them
in machine language and each instruction is
composed of a number of binary digits, each of
which can only be a 0 or a 1.These binary
numbers are often called bits. Each set of binary
digits is translated by the CPU into an instruction
that tells it to do a very specific job, such as
compare these two numbers, or put this number
in that memory location.

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Conversion from Decimal to Binary
 Repetitive division: 27 = 11011

27
Note: The remainders incurred when the given
13 1 decimal number is divided by 2 shall form the
binary equivalent. The division will only terminate
6 1 when the quotient becomes 0.

3 0
1 1
0 1

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Challenge
1 20 27 128
 Convert the following decimal
numbers to their binary 2 21 28 256
equivalent.
 49 4 22 29 512
 126
8 23 210 1024
 500

 1239 16 24 211 2048


 2463
32 25 212 4096

64 26 213 8192

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Quiz (1/2 Crosswise)

 To Decimal  To Binary
 11101101  342
 10011101  1703
Addition
CARRY
 Basic Examples:
 0 + 0 = 0

 1 + 0 = 1 a b. 1 1 1 1 1

 0 + 1 = 1 1 1 0 0 1 0 1 1 0 0 1 1
+ +
 1 + 1 = 10 0 1 0 0 1 1 1 1 0 1
1 1 1 0 1 1 1 0 1 0 0 0 0

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Challenge
 Add the following but convert the decimal values to their
binary equivalent first.
 34 and 107

 54 and 17

 301 and 207

 48 and 75

 231 and 1072

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Multiplication
 Basic Example:
 0 x 0 = 0

 0 x 1 = 0 a.

 1 x 0 = 0
1 1 0 1 0 1
 1 x 1 = 1 x

1 1
CARRY 1 1 1 0 1 0 1
+
1 1 0 1 0 1
1 0 0 1 1 1 1 1
Subtraction
 Basic: Examples:
 0–0=0 a.

 1–0=1 1 1 0 1 1 1
- 1 0 0 1 0 1
 1–1=0
0 1 0 0 1 0
 0–1=?

b.
borrow
0 10 0 10

1 0 0 1 1 0
- 1 0 1 0 1
0 1 0 0 0 1

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Still on Subtraction

 What if we are to subtract 1101 from 1001?

At this point we need to borrow 1


but from where?

0 10
1 0 0 1
- 1 1 0 1

1 0 0

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Negative Values in Binary Number
System
 Signed Magnitude (S.M.)
 One’s Complement (O.C.)
 Two’s Complement (T.C.)
 When working with the above, we restrict the

numbers in an n-bit system. In the next slides,


assume that we are working with a 6-bit
system.
Signed Magnitude
 Use the most significant bit as the sign bit, 0
for positive, 1 for negative.
 Examples
001100 12

101100 -12

000101 5

100101 -5

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
One’s Complement
 To get the negative equivalent of a binary number, flip
the bits, meaning, if the bit is one 1, simply reverse it to 0
and vice-versa.
 Examples
001100 12

110011 -12

000101 5

111010 -5

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Two’s Complement
 To get the negative equivalent of a binary number, flip the bits then
add 1 to the result.
 Examples

001100 12

110100 -12

Given: 001100 000101 5


Flipped: 110011
Add 1: 1 111011 -5
110100

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Still on Subtraction
 12 – 5 is simply 12 + (-5). Since we have discussed how to get the
negative of a binary number, let’s try solving this using the 3
methods previously discussed.
 S.M.
 001100 + 100101 = 110001
 O.C. Since we are working
 001100 + 111010 = 1000110 with a 6-bit system, the
7th bit is an overflow and
 T.C. therefore disregarded.
 001100 + 111011 = 1000111

“There are only 2 types of people in the world, those who


understand binary, those who do not.”
Challenge

Do the same for 12 + (-12). Compare the


results by converting the values (sum) to their
decimal equivalent. Which method gives out
the correct answer?

“There are only 2 types of people in the world, those who


understand binary, those who do not.”

You might also like