Friday, September 12, 2014

1.4.1 PROGRAM DEVELOPMENT PROCESS

     1.      Understand the problem
·         The problem should be clearly defined. It is divided into three components:
ü      Input
ü      Output
ü      Processing
·         Programmers should clearly understand, “what are the inputs to the program”, “what is expected as output”, and “how to process inputs to generate necessary outputs”.

2.      Outline the solution
The programmer should define the major steps required to solve the problem, any subtasks, the major variables and data structures that are to be used in the program, and most importantly the underlined logic.

3.      Develop the algorithm
The algorithm lays out a segment of precise steps that describes exactly the tasks to be performed and the order in which they are to be carried out to solve a problem.

4.      Test the algorithm for correctness
·         The programmer must make sure that the algorithm is correct.
·         The objective is to identify major logic errors early, so that they may be easily corrected.
·         Test data should be applied to each step, to check whether the algorithm actually does what it is supposed to.

5.      Code the algorithm
After all the design considerations have been met and when the algorithm has been finalized, the code is written in a suitable programming language.

6.      Compile
·         While compiling syntax errors can be identified.
·         If there are no syntax errors, the program gets compiled and it produces an executable program.

7.      Run the program
·         Executable program generated after compiling can then be executed.
·         While the program is running, runtime errors and sometimes logic errors cab be identified, which are corrected accordingly.

8.      Test, document and maintain the program
·         Test the running program using the test data to make sure program is producing correct output.
·         All the steps involved in developing the program algorithm and code should be documented for future reference.
·         Programmers should also maintain and update the program according to new or changing requirements.

Thursday, September 11, 2014

1.3.4 SIGNED MAGNITUDE CONVENTION

      1.      To represent negative numbers, WE NEED A NOTATION FOR NEGATIVE VALUES.
2.      The convention is to make the sign bit 0 for positive and 1 for negative.
3.      The user determines whether the number is signed or unsigned:
a.       If the binary number is signed, then the leftmost bit represents the sign and the rest of the bits represent the number.
b.      If the binary number is assumed to be unsigned, then the leftmost bit is the most significant bit of the number.

0101
ü  5 (unsigned number)
ü  +5 (signed number) (leftmost bit is 0)

1101
ü  13 (unsigned number)
ü  -5 (signed number) (leftmost bit is 1)

NOTE: There is no confusion in identifying the bits if the type of representation for the number is known in advance.

1.3.3 BINARY COMPLEMENTS

Complements are used in the digital computers in order to simplify the subtraction operation and for the logical manipulations.

1's complement

The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1's. This is called as taking complement or 1's complement.

Example of 1's Complement is as follows:
 1011001         à        0100110
 10000             à        01111
 11011             à        00100

2's complement

The 2's complement of binary number is obtained by adding 1 to the Least Significant Bit (LSB) of 1's complement of the number.

2's complement = 1's complement + 1

Example of 2's Complement is as follows:
  0101              à        1010 + 1          =          1011
  101100          à        010011 + 1      =          010100
  0000              à        1111 + 1          =          10000
  111                à        000 + 1            =          001

Wednesday, September 10, 2014

1.3.2 BINARY ARITHMETIC

Binary Addition
  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 0, and carry 1 to the next more significant bit

For example,
00011010 + 00001100 = 00100110
        
        1  1
 
carries
   0  0  0  1  1  0  1  0
   =   
26(base 10)
+ 0  0  0  0  1  1  0  0


   =   
12(base 10)
   0  0  1  0  0  1  1  0
   =   
38(base 10)
 

Note:  The rules of binary addition (without carries) are the same as the truths of the XOR gate.

Binary Subtraction
  • 0 - 0 = 0
  • 0 - 1 = 1, and borrow 1 from the next more significant bit
  • 1 - 0 = 1
  • 1 - 1 = 0

For example,
00100101 - 00010001 = 00010100
        
        0
 
borrows
  0  0  1 10  0  1  0  1
   =   
37(base 10)
- 0  0  0  1  0  0  0  1


   =   
17(base 10)
  0  0  0  1  0  1  0  0
   =   
20(base 10)

 

Binary Multiplication

  • 0 x 0 = 0
  • 0 x 1 = 0
  • 1 x 0 = 0
  • 1 x 1 = 1, and no carry or borrow bits

For example,
00101001 × 00000110 = 11110110
        
0  0  1  0  1  0  0  1
   =   
41(base 10)
× 0  0  0  0  0  1  1  0


   =   
6(base 10)
0  0  0  0  0  0  0  0
 
0  0  1  0  1  0  0  1   
 
0  0  1  0  1  0  0  1      


 
0  0  1  1  1  1  0  1  1  0
   =   
246(base 10)

 

Note:  The rules of binary multiplication are the same as the truths of the AND gate.

 
Binary Division
Binary division is the repeated process of subtraction, just as in decimal division.

For example,
00101010 ÷ 00000110 = 00000111
        
 
 
 
 
 
 
 
 1 
 1 
 1 
   =   
7(base 10)


1  1  0 
)
 0 
 0 
 1 
1
 1 
 0 
 1 
 0 
   =   
42(base 10)
 
 
 
 
-  
 1 
 1 
 0 
 
 
   =   
6(base 10)
 


 
 
 
 
 
 1 
 
 
 
 
borrows
 
 
 
1 
 0 
1
 1 
 
 
 
 
-  
 1 
 1 
 0 
 
 


 
 
 
 
 
   
 1 
 1 
 0 
 
 
 
 
-  
 1 
 1 
 0 
 


 
 
 
 
 
 
 
 0