revision language generations two’s and one’s complement and sign and magnitude
TRANSCRIPT
Revision• Language generations• Two’s and One’s Complement and Sign
and Magnitude
Language Generations:
Evolution of Programming Languages
Lan
gu
age
Gen
era
tions
First Generation (1s and 0s)
Second Generation
(Mnemonics) Third Generation
(High-Level Language)
Fourth Generation (Drag
and Drop)Fifth Generation
(Artificial Intelligence)
First Generation The first generation of languages
was very difficult to understand and also to code
This language was based on machine code language, hence the programmer would need to use binary
For this particular generation, punched tape was used, where a hole would represent a 1 and no-hole meant a 0.
Second Generation / Assembly Language
The second generation language, was also based on machine code,
This language was much easier as it used mnemonics (short words)
Programming was much easier because the programmer did not have to remember a list of binary digits
Keywords are used in this language such as ADD, SUB, JMP, MUL, etc
Third Generation / High-level Language
The third generation of languages was a very big improvement from the second generation
This generation incorporated the use of English-like statements
Examples of 3GLs are C, C++, Pascal and JAVA.
Examples of the 3rd Generations FORTRAN - mathematics formulas, scientific
problems, engineering problems COBOL – business oriented BASIC – very easy to understand, ideal to learn
programming PASCAL – mostly used for teaching purposes C – used to write operating systems, database
management system, scientific applications LISP – artificial intelligence LOGO – teach children problem-solving and
programming skills C ++ - An improved C, very popular and powerful JAVA – Very popular and powerful, also cross-platform
Fourth Generation The fourth generation language is a is
much closer to the human language
A typical example of the ease of use of 4th generation languages is the creation of a GUI.
To create a GUI in JAVA would be quite difficult because of the code required for each component, with any 4GL creating an interface is a simple matter of drag and drop
This generation is used a lot with databases
Fifth Generation Lastly we have the fifth
generation languages, which are the closest to the human language
This generation is used in artificial intelligence
Number Systems:Two’s and One’s
Complement and Sign and Magnitude
ComplementationComplementation is used to represent
positive and negative numbers in binary
This system requires numbers to be represented by a fixed register size.
There are two forms of complementation, one’s complement and two’s complement.
Ones Complement One’s complement is used to represent
negative numbers
Lets say we have 4510
When using 8 bits 4510 = 001011012
If we change 4510 to -4510 The binary representation changes by converting 0s to 1s and 1s to 0s;
001011012 110100102. after ones complement
Examples
Decimal Unsigned Binary
One’s Complement
-10910 11011012 00100102
-22910 111001012 000110102
Decimal Unsigned Binary
One’s Complement
-8910 010110012 101001102
-6410 10000002 01111112
-8910
-6410
Two’s Complement Two’s complement allows us to
perform subtractions with binary numbers
With two’s complement we start converting 1s to 0s and 0s to 1s after the first 1
Lets take the previous example of -4510,
Decimal Unsigned Binary
Two’s complement
-4510 001011012 110100112
Examples
Decimal Binary Two’s Complement
-1010 000010102 111101102
-4210 001010102 110101102
-5510 001101112 110010012
-6010 001111002 110001002
-5510
-6010
Sign and MagnitudeWhen we have a fixed register we
might want to store our binary number in a certain way
The three ways are using;1. sign and magnitude (first digit is
0 = positive, first digit is1 = negative)
2. one’s complement 3. two’s complement.
Example Lets say I have an 8 bit register
and want to store -1410
The number changes since it is negative, we first change it to binary = 000011102
Sign and Magnitude 10001110 Note that the fist digit is 1 because in this
case 14 is a negative number.
One’s Complement 11110001 In this case we simply applied NOT on the
binary value of 14.
Two’s Complement 11110010 We change the binary number 14 into two’s complement
Example 2 Lets say I have an 8 bit register
and want to store 1410
The number does not change since it is a positive number, we first change it to binary = 000011102Sign and Magnitude 00001110 Note that the fist digit is 0 because in this
case 14 is a positive number.
One’s Complement 00001110 In this case we simply leave the binary number the same
Two’s Complement 00001110 In this case we simply leave the binary number the same