1 Intro and Binary Operations
1 Intro and Binary Operations
The problems themselves can come from many fields of application, e.g.,
biology, chemistry, physics, engineering, medicine, education,
entertainment, the internet, forensics, financial markets, etc
The stakes are often high, so the results must be accurate, reliable, and
robust.
Here are some examples of real life disasters that occurred because of poor
computing practices (and not because of programming errors per se).
1
2. Stability vs. convergence: Some numerical methods may be more stable
but converge slower, while others may converge quickly but be highly
sensitive to initial conditions.
3. Robustness vs. complexity: More complex numerical methods may
provide better results in a wider range of situations, but they may also be
more difficult to implement and require a deeper understanding of the
underlying mathematical principles.
4. Applicability vs. simplicity: Some numerical methods may be more
applicable to a wider range of problems but may also be more complex
and difficult to implement, while simpler methods may be limited in their
applicability.
5. Model complexity vs. computational efficiency: More complex numerical
methods may be able to handle more complex models, but may require
significantly more computational time and resources.
Other Includes;
2
1. BINARY SYSTEMS
Modern computers of high-speed deal with real number in the binary system in
contrast to the decimal systems that humans prefer to use. The binary ‘sys’ uses
two digits; O's and 1's only to represent numbers. It is called “bits”. E.g.,
11100101 has 8 bits. 8 bits make one byte.
Solution
a) 10011011₂ = 1 × 27 + 0 × 26 + 0 × 25 + 1 × 24 + 1 × 23 + 0 × 22 +
1 × 21 + 1 × 20
= 128 + 0 + 0 + 16 + 8 + 0 + 2 + 1
= 15510
b) 1001.11101₂ = 1 × 2 + 0 × 22 + 0 × 21 + 1 × 20 + 1 × 2−1 + 1 ×
3
= 9.96910
3
Conversion from Decimal (Base 10) to Binary Base
2 15
2 7r1
2 3r1
2 1r1
0r1
1510 = 11112
2 25
2 12 r 1
2 6r0
2 3r0
1r1
0r1
1510 = 110012
2 1 2 5 2 5
2 0r1 2 2r1 2 2r1
2 1r0 2 1r0
0r1 0r1
So 155 is;
1 = 0001
5 = 0101
5 = 0101
NOTE: You will add zero to the front so as to make each 4 digits
4
Conversion from Binary to Octal System
Solution
STEP 1 - Convert to base 10
10110₂ = 1 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 0 × 20 = 2210
= 26
101102 = 268
10000101 = 1 × 27 + 0 × 26 + 0 × 25 + 0 × 24 + 0 × 23 + 1 × 22 + 0
× 21 + 1 × 20 = 133
8 133
8 16 r 5
8 2r0
0r2
100001012 = 2058
5
Conversion from Octal to Binary
Solution
STEP 1 - Convert to base 10
3078 = 3 × 82 + 0 × 81 + 7 × 80
= 192 + 0 + 7
= 19910
2 199
2 99 r 1
2 49 r 1
2 24 r 1
2 12 r 0
2 6r0
2 3r0
2 1r1
0r1
19910 = 110001112
EXCERCISE
1) Convert 47628 to binary.
Solution
STEP 1 - Convert to base 10
11101.01112
= 1 × 24 + 1 × 24 + 1 × 22 + 0 × 21 + 1 × 20 + 0 × 2−1
+ 1 × 2−2 + 1 × 2−3 + 1 × 2−4
= 16 + 8 + 4 + 1 + 1⁄2 + 1⁄4 + 1⁄8 + 1⁄16
= 29.4375210
6
STEP 2 - Convert to base 8
8 29
8 3r5
0r3
29 = 358
the fraction part is as follow
0.43752 × 8 = 3.5 𝑐𝑎𝑟𝑟𝑦 3
0.5 × 8 = 4 𝑐𝑎𝑟𝑟𝑦 4
Continue until no fractional part or till you are okay with the precision
2 5
2 2r1
2 1r0
0r1
= 101.11012
Excercise
1) Convert 11011011.110112 to octal.
7
BINARY OPERATIONS (Arithmetic)
A microprocessor uses the following four binary arithmetic to carry out its
operations. They include addition, subtraction, multiplication, division.
1) Addition
a. Add 10102 𝑎𝑛𝑑 10012
1 0 1 0
+ 1 0 0 1
1 0 0 1 1
1 1 0 0 1 0 0 1
+ 1 0 0 1 1 1 0
1 0 0 0 1 0 1 1 1
2) Subtraction
a. Subtract 10012 𝑓𝑟𝑜𝑚 10102
1 0 1 0
- 1 0 0 1
0 0 1 0
0 0 1 1 0 1 0
- 0 0 1 1 0 0
0 0 0 1 1 1 0
1 1 1 0 1 1 0
-1 0 1 0 1 1 1
0 0 1 1 1 1 1
8
3) Multiplication
a. Evaluate 11001012 × 100112
1 1 0 0 1 0 1
X 1 0 0 1 1
1 1 0 0 1 0 1
1 1 0 0 1 0 1
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 1 0 0 1 0 1
1 1 1 0 1 1 1 1 1 1 1
4) Division
To divide two numbers, which result is an exact division, we basically need to
follow four steps: division, multiplication, subtraction, and next digit.
To perform a binary division, we need to follow the same process as we do for
dividing regular numbers but, in this case, we only need to decide if it's going to
be a 1 or a 0.
ANS = 101
Hexadecimal is the name of the numbering system that is base 16. This system,
therefore, has numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, and 15. That
means that two-digit decimal numbers 10, 11, 12, 13, 14, and 15 must be
represented by a single numeral to exist in this numbering system. To address
the two-digit decimal values, the alphabetic characters A, B, C, D, E, and F are
used to represent these values in hexadecimal and are treated as valid numerals.
These digits are represented as follows:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7 8 9 A B C D E F
16 207
16 12 R 15 -> F
0 R 12 -> C
Excercise
Miscellaneous
Two’s Complement
Example
Step 1
Decide how many bits you are going to use for all your operations. For our
purposes we will always use 8 bits.
If we were using 8-bits the left-most bit will contain the sign. This would leave
7 bits to hold the number.
XXXX XXXX
|
This is the sign bit
11
This sign bit is reserved and is no longer one of the digits that make up the binary
number. Using two’s complement, the computer recognizes the presence of a
one (1) in the leftmost bit which tells the machine that before it does
mathematics it needs to convert negative numbers into their two’s compliment
equivalent.
Step 3
Convert the negative number into it’s two’s complement form
So therefore
Excercise
12