Unit 2 - CFedited
Unit 2 - CFedited
A number is a mathematical value used for counting and measuring objects, and for performing
arithmetic calculations. Numbers have various categories like natural numbers, whole numbers,
rational and irrational numbers, and so on. Similarly, there are various types of number systems that
have different properties, like the binary number system, the octal number system, the decimal
number system, and the hexadecimal number system.
What are Number Systems?
A number system is a system representing numbers. It is also called the system of numeration and it
defines a set of values to represent a quantity. These numbers are used as digits and the most
common ones are 0 and 1, that are used to represent binary numbers. Digits from 0 to 9 are used to
represent other types of number systems.
Definition of Number Systems
A number system is defined as the representation of numbers by using digits or other symbols in a
consistent manner. The value of any digit in a number can be determined by a digit, its position in the
number, and the base of the number system. The numbers are represented in a unique manner and
allow us to operate arithmetic operations like addition, subtraction, and division.
Number system
The base of the number system defines the total number of different digits or symbols available in
the number system.
⇒5810 = 1110102
Therefore, the integer part of equivalent binary number is 111010.
Step 2 − Multiplication of 0.25 and successive fractions with base 2.
Operation Result Carry
0.25 x 2 0.5 0
0.5 x 2 1.0 1
- 0.0 -
⇒.2510 = .012
Therefore, the fractional part of equivalent binary number is .01
⇒58.2510 = 111010.012
Therefore, the binary equivalent of decimal number 58.25 is 111010.01.
Example
Consider the Hexa-decimal number 1A5.2
Mathematically, we can write it as
1A5.216 = (1 × 162) + (10 × 161) + (5 × 160) + (2 × 16-1)
⇒ 1A5.216 = 256 + 160 + 5 + 0.125 = 421.125
⇒ 1A5.216 = 421.12510
Therefore, the decimal equivalent of Hexa-decimal number 1A5.2 is 421.125.
Computer Codes
Computer Data:
1. Numeric Data consists of only numbers 0, 1, 2, …, 9
2. Alphabetic Data consists of only the letters A, B, C,…, Z, in both uppercase and lowercase,
and blank character
3. Alphanumeric Data is a string of symbols where a symbol may be one of the letters A, B, C,
…, Z, in either uppercase or lowercase, or one of the digits 0,1, 2, …, 9, or a special
character, such as + - * / , . ( ) = etc.
Computer Codes:
Computer codes are used for internal representation of data in computers
As computers use binary numbers for internal data representation, computer codes use binary
coding schemes
In binary coding, every symbol that appears in the data is represented by a group of bits
The group of bits used to represent a symbol is called a byte
As most modern coding schemes use 8 bits to represent a symbol, the term byte is often used
to mean a group of 8 bits
Commonly used computer codes are BCD, EBCDIC, Gray and ASCII
1. BCD
BCD stands for Binary Coded Decimal
It is one of the early computer codes
It uses 4 bits to represent a symbol
2. Gray Code
o It is the non-weighted code and it is not arithmetic codes. That means there are no specific
weights assigned to the bit position.
o It has a very special feature that, only one bit will change each time the decimal number is
incremented as shown in fig.
o As only one bit changes at a time, the gray code is called as a unit distance code.
o The gray code is a cyclic code.
o Gray code cannot be used for arithmetic operation
3. ASCII:
ASCII stands for American Standard Code for Information Interchange.
ASCII is of two types – ASCII-7 and ASCII-8
ASCII-7 uses 7 bits to represent a symbol and can represent 128 (27) different
characters
ASCII-8 uses 8 bits to represent a symbol and can represent
(28) different characters
First 128 characters in ASCII-7 and ASCII-8 same
Coding of numeric and alphabetic characters in ASCII
Boolean Algebra
An algebra that deals with binary number system
George Boole (1815-1864), an English mathematician, developed it for:
Simplifying representation
Manipulation of propositional logic
In 1938, Claude E. Shannon proposed using Boolean algebra in design of relay switching
circuits
Provides economical and straightforward approach
Used extensively in designing electronic circuits used in computers
Fundamental Concepts of Boolean Algebra
Use of Binary Digit
Boolean equations can have either of two possible values, 0 and 1
Logical Addition
Symbol „+‟, also known as „OR‟ operator, used for logical addition. Follows law of
binary addition
Logical Multiplication
Symbol „.‟, also known as „AND‟ operator, used for logical multiplication.
Follows law of binary multiplication
Complementation
Symbol „~‟, also known as „NOT‟ operator, used for complementation. Follows law
of binary compliment
Operator Precedence
Each operator has a precedence level
Higher the operator‟s precedence level, earlier it is evaluated
Expression is scanned from left to right
First, expressions enclosed within parentheses are evaluated
Then, all complement (NOT) operations are performed
Then, all „×‟ (AND) operations are performed
Finally, all „+‟ (OR) operations are performed
Postulates of Boolean Algebra
Boolean Functions
A Boolean function is an expression formed with:
Binary variables
Operators (OR, AND, and NOT)
Parentheses, and equal sign
The value of a Boolean function can be either 0 or 1
A Boolean function may be represented as:
An algebraic expression, or
A truth table
Representation as an Algebraic Expression
W=X+
Y ·Z
Variable W is a function of X,Y and Z ,can also be written as W = f (X, Y, Z)
The RHS of the equation is called an expression
The symbols X, Y, Z are the literals of the function
For a given Boolean function, there may be more than one algebraic expressions
The number of rows in the table is equal to 2n, where n is the number of literals in the
function
The combinations of 0s and 1s for rows of this table are obtained from the binary numbers by
counting from 0 to 2n - 1
Boolean Operators
Boolean operators are words that connect search terms (keywords) to create a logical phrase that a
database can understand. They allow you to create a complex search that could include multiple
concepts and alternative keywords.
Boolean Operator What it Does How to use
AND Finds items that use both keywords. adult learning AND online courses
OR Finds items that use either of the keywords. adult learners OR adult students
NOT Excludes articles that use the keyword. NOT masters programs
Logic Gates
Logic gates are electronic circuits that operate on one or more input signals to produce
standard output signal
Are the building blocks of all the circuits in a computer
Some of the most basic and useful logic gates are AND, OR, NOT, NAND ,NOR, XOR and
XNOR gates.
Most electronic devices we use today will have some form of logic gates in them. For
example, logic gates can be used in technologies such as smartphones, tablets or within
memory devices.
This is the most basic gate, with one input and one output. It produces a „1‟ output if the
input is „0‟ and vice-versa. That is, it produces an inverted version of the input at its
output.
This is an AND gate followed by a NOT gate. If inputs A and B are both „1‟, the output Y
is not „1‟. The gate gets its name from this NOT AND behavior.
NAND gates are also called Universal Gates since by using these gates you can realize
other basic gates like OR, AND and NOT.
NOR Gate (Block Diagram Symbol and Truth Table)
It has two or more inputs and one output. A NOT- operation applied after OR gate gives a
NOT-OR gate (or simply NOR gate). Its output Y is „1‟ only when both inputs A and B
are „0‟, i.e., neither one input nor the other is „1‟.
NOR gates are considered as universal gates because you can obtain all the gates like
AND, OR, NOT by using only NOR gates
XOR gate:
An XOR gate is a two-input single-output logic gate whose output is assumed to be HIGH(one) only
when one of its inputs is HIGH(one).
XNOR Gate: An XNOR gate is a two-input single-output logic gate whose output is high when
both inputs are set to high(1).
Logic Circuits
When logic gates are interconnected to form a gating / logic network, it is known as a
combinational logic circuit
The Boolean algebra expression for a given logic circuit can be derived by systematically
progressing from input to output on the gates
The three logic gates (AND, OR, and NOT) are logically complete because any Boolean
expression can be realized as a logic circuit using only these three gates
Finding Boolean Expression of a Logic Circuit (Example 1)
Finding Boolean Expression of a Logic Circuit (Example 2)
Computer Languages
There are mainly three different languages with the help of which we can develop computer
programs. And they are:
• Machine Level language
• Assembly Level Language and
• High-Level Language
Machine Level Language
The computer can understand only the language of Digital Electronics. Digital Electronics deals with
the presence and absence of voltages. Within the computer there are two logics can play their role.
These logics are −
• Positive Logic − Here presence of voltage will be denoted by 1 and absence of
voltage will be denoted by 0
• Negative Logic − Here presence of voltage will be denoted by 0 and absence of
voltage will be denoted by 1
• But obviously, the computer can follow any one of the logic at a time, not both the logics
simultaneously.
• To make the computer understand, a program can be written using only 0s and 1s.
• The data can also be specified and represented using only 0s and 1s.
• Such a program is called Machine Language program. Machine language was the first in the
evolution of computer programming languages. Computer directly understands a program
written in the machine language.
• So as a result, the machine language program does not require any translator to convert from
one form to another. In fact, even to this day, basically, computers understand only the 0s and
1s.
Translator Programs
Language Processors –
Compilers, interpreters, translate programs written in high-level languages into machine code that a
computer understands. And assemblers translate programs written in low-level or assembly language
into machine code. In the compilation process, there are several stages. To help programmers write
error-free code, tools are available.
Assembler
The Assembler is used to translate the program written in Assembly language into machine code.
The source program is an input of an assembler that contains assembly language instructions. The
output generated by the assembler is the object code or machine code understandable by the
computer. Assembler is basically the 1st interface that is able to communicate humans with the
machine. We need an Assembler to fill the gap between human and machine so that they can
communicate with each other. code written in assembly language is some sort of
mnemonics(instructions) like ADD, MUL, MUX, SUB, DIV, MOV and so on. and the assembler is
basically able to convert these mnemonics in Binary code. Here, these mnemonics also depend upon
the architecture of the machine.
For example, the architecture of intel 8085 and intel 8086 are different.
Interpreter
The translation of a single statement of the source program into machine code is done by a language
processor and executes immediately before moving on to the next line is called an interpreter. If there
is an error in the statement, the interpreter terminates its translating process at that statement and
displays an error message. The interpreter moves on to the next line for execution only after the
removal of the error. An Interpreter directly executes instructions written in a programming or
scripting language without previously converting them to an object code or machine code.
Example: Perl, Python and Matlab.
Compiler
The language processor that reads the complete source program written in high-level language as a
whole in one go and translates it into an equivalent program in machine language is called a
Compiler. Example: C, C++, C#, Java.
In a compiler, the source code is translated to object code successfully if it is free of errors. The
compiler specifies the errors at the end of the compilation with line numbers when there are any
errors in the source code. The errors must be removed before the compiler can successfully
recompile the source code again
3. Processing:- Rectangular shape is used to show the processing section of an algorithm. In it, the
formulas and instructions are written, through which the data is being processed. When processing
has more than one instruction, then they are written in the same box. The instructions that are written
before, are executed first and which are written later, it is executed later
4. Decision :-The Rhombus/Diamond is used to show the decision section. It is used in the place
where we want to perform certain task only when a particular condition holds true or false. In this
case for each possible situation arising, different flow-lines are used to represent the flow of
execution.
5. Flow-lines :- The arrow shape is used to show the flow lines, these are used to
connect different shapes such as input output box, terminal, decision box, and
connector etc. It is also used to show the flow of the execution of the program. The
flow of execution of the program is determined by the direction of arrow mark on
the flow line.
6. Connectors :- The spherical / Circle shapes are used to represent the connectors. These are used
when the flowchart is so large that it cannot come to one page or the flow line of flowchart starts
cutting each other.
These shapes are , on which letters or numerals are written, so that they can know
their links in between. Similar letters or numbers written in a program, display the
continuous flow of the connector program.