Sunteți pe pagina 1din 10

UNIT - I

UNIT - I Block diagram of a computer 1. Input unit: Arithmetic and Logic unit (ALU)

Block diagram of a computer

1. Input unit:

Arithmetic and Logic unit (ALU) Input Outp Control unit ut unit Memory unit
Arithmetic and
Logic unit (ALU)
Input
Outp
Control
unit
ut unit
Memory unit

CPU

This is the receiving section of the computer. It obtains information from various input devices and places this information at the disposal of the other units. Most information is carried into computers today through keyboards and mouse devices. Information can also be entered by speaking to your computer and by scanning images.

2.Output unit:

This is the shipping section of the computer. It takes information that has been processed by the computer and place it on various output devices to make the information available for use. Most information output from computers today is displayed on screens, printed on paper.

3.Memory unit:

This is the warehouse section of the computer. It retains information that has been entered through the input devices. This memory unit also retains processed information until that information can be placed on output devices, by the output devices. This Memory unit is also called memory or primary memory.

4.Arithmetic and Logic unit (ALU) :

This is manufacturing unit of the computer. It is responsible for performing calculations such as addition, subtraction, division and multiplication. It contains decision mechanisms to find the logical relation between two variables.

5.Control unit:

The control unit controls all the component activities of the computer. It sends command and control signals and finds the sequence of instructions to be executed.

6.Central processing unit:

Control unit, memory unit and ALU constitute central processing unit

unit, memory unit and ALU constitute central processing unit Notes Prepared by T. Ratna Reddy. Associate
unit, memory unit and ALU constitute central processing unit Notes Prepared by T. Ratna Reddy. Associate

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 1

UNIT - I

UNIT - I OPERATING SYSTEM (OS) An operating is a program which connects the user and

OPERATING SYSTEM (OS)

An operating is a program which connects the user and the electronic hardware in a computer. It has a set of programs which supervise the activities of a computer and activate the operations of the hardware components such as main memory, disk drives, keyboard, monitor, printer and so on.

key board Mouse Operating user Disk drives system Monitor Applicatio n programs
key board
Mouse
Operating
user
Disk drives
system
Monitor
Applicatio
n programs

Three major stages of evolution of OS:

1. Batch processing: performing one task or job at a time.

2. Multiple processing: it involves simultaneous operation of many jobs on the computer.

3. Time sharing system: this OS allow many users to share the computer at a time.

PROGRAMMING LANGUAGES

There are 3 types of programming languages

1. Machine languages:

i) These are the low-level languages directly

used by the computer.

ii) The instructions of these languages consists of stings of binary digits 0 and 1.

iii)These languages do not require translators because machine code will be directly understood

by the computer. iv)These languages are machine dependent.

2. Assembly languages:

i) Programming in low-level languages is very difficult. Therefore middle-level languages are developed.

ii) The instructions of these languages consists mnemonics. Mnemonics are the English like abbreviations to represent the elementary operations of the computer. Example:

LOAD A

ADD

STORE C

B

iii) Assembly languages require translator programs, called assemblers. Assemblers convert assembly language programs machine level languages.

3. High-level languages:

i) To write complex programs in assembly languages is difficult. So high-level languages are developed.

ii) In these programs single statements accomplish, that particular task. Example:

C = A + B;

iii)Translator programs called compilers convert high-level language programs to machine language. iv) PASCAL, FORTRAN,C and C++ are the high level languages.

iv) PASCAL, FORTRAN,C and C++ are the high level languages. Notes Prepared by T. Ratna Reddy.
iv) PASCAL, FORTRAN,C and C++ are the high level languages. Notes Prepared by T. Ratna Reddy.

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 2

UNIT - I

UNIT - I Assembler, Interpreter, Compiler, Loader, Linker Assembler: Assembler is software that converts a program

Assembler, Interpreter, Compiler, Loader, Linker

Assembler:

Assembler is software that converts a program written in assembly language into machine code. There is usually one-to-one correspondence between simple assembly statements and machine language instructions. Since the machine language is dependent on the processor architecture, assembly language programs also defer for different architecture.

Interpreter:

Interpreter performs line by line execution of the source code. Interpreter reads source code line by line, converts it into machine understandable form, executes the line, and then proceeds with the next line. Some languages that uses interpreter are BASIC and PYTHON

Compiler:

A program written in high level language has to be converted to a language that computer can

understand i.e. binary form. Compiler is software that translates the program written in high level language to machine language. The program written in high level language is called source code and the compiled program is called object code. The compilation process generally involves two parts. Breaking down the source code into small pieces and constructing the object code. The compiler also reports syntax errors, if any in the source program.

Source code Linker:
Source code
Linker:
Assembler Interpreter Compiler
Assembler
Interpreter
Compiler

Object code

A linker is a program that link several object modules and libraries to form a single executable

program.

Loader:

Loaders are a part of operating system that brings an executable file residing on disk into memory and starts it running.

Source program

     

Object code

   
Compiler   Linker

Compiler

 
Compiler   Linker
Compiler   Linker

Linker

 
 
 
 
     

Loader

   

Executable

Memory

Memory code
Memory code

code

  Loader     Executable Memory code Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT
  Loader     Executable Memory code Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 3

UNIT - I

UNIT - I Number systems There are four types of number systems ,depending on the number

Number systems

There are four types of number systems ,depending on the number of digits used(radix), to represent a number. The base or radix of a number system is defined as the number of digits that it uses to represent the number.

s.no

Name of number system

Numbers used

Radix or base

1.

Decimal number system

0

to 9

10

2.

Binary number system

0

and 1

2

3.

Octal number system

0

to 7

8

4.

Hexadecimal number system

0

to 9,A,B,C,D,E,F

16

Decimal

binary

octal

hexadecimal

0

0000

0

0

1

0001

1

1

2

0010

2

2

3

0011

3

3

4

0100

4

4

5

0101

5

5

6

0110

6

6

7

0111

7

7

8

1000

10

8

9

1001

11

9

10

1010

12

A

11

1011

13

B

12

1100

14

C

13

1101

15

D

14

1110

16

E

15

1111

17

F

15 D 14 1110 16 E 15 1111 17 F Notes Prepared by T. Ratna Reddy.
15 D 14 1110 16 E 15 1111 17 F Notes Prepared by T. Ratna Reddy.

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 4

UNIT - I

UNIT - I Binary to decimal 110101 2 = ( ) 1 0 Octal to decimal
UNIT - I Binary to decimal 110101 2 = ( ) 1 0 Octal to decimal

Binary to decimal

110101 2

=

(

) 10

Binary to decimal 110101 2 = ( ) 1 0

Octal to decimal

468 8 = (

) 10

Octal to decimal 468 8 = ( ) 1 0

Hexadecimal to decimal

ABC 16 =

(

) 10

Hexadecimal to decimal ABC 1 6 = ( ) 1 0

Decimal to binary

125 10 = ( 1111101) 2

Decimal to binary 125 1 0 = ( 1111101) 2

Decimal to Octal

1234 10 = ( 2322) 8

Decimal to Octal 1234 1 0 = ( 2322) 8

Decimal to Hexadecimal 1234 10 = ( 4D2 ) 16

Decimal to Hexadecimal 1234 1 0 = ( 4D2 ) 1 6

Hexadecimal to Binary

Octal to Binary

705 8 = ( ) 2 Technique: Convert each Octal digit to a 3-bit Associate equivalent Professor, binary CBIT representation

equivalent Professor, binary CBIT representation Octal to Hexadecimal 1076 8 =( ) 1 6 10AF 1

Octal to Hexadecimal 1076 8 =( ) 16

10AF 16 = ( ) 2

Technique: Convert each hexadecimal digit to a 4-bit equivalent binary

Convert each hexadecimal digit to a 4-bit equivalent binary Notes Prepared by representation T. Ratna Reddy.
Convert each hexadecimal digit to a 4-bit equivalent binary Notes Prepared by representation T. Ratna Reddy.

Notes Prepared by

representation

T. Ratna Reddy.

binary Notes Prepared by representation T. Ratna Reddy. Mobile Technique: No: 9985 666778 Use Page 5

Mobile Technique: No: 9985 666778 Use Page 5 binary as an intermediary

Prepared by representation T. Ratna Reddy. Mobile Technique: No: 9985 666778 Use Page 5 binary as

UNIT - I

UNIT - I Floating point representation To convert a decimal fraction to another base b, repeated

Floating point representation To convert a decimal fraction to another base b, repeated multiplication by base b is done instead of division. Let us take an example that converts a decimal fraction 0.6875 10 to binary. Decimal to binary

Multiplication process

integer part

0.6875 X 2 = 1.375

1

0.375 X2 = 0.750

0

0.75X 2 = 1.5

1

0.5X 2 = 1.0

1

Therefore 0.6875 10 = 0.1011 2

Input/output

Processing

Checking/decision making

Algorithms and flow charts:

Algorithm is a step by step process to do a particular task. The steps must be clear and definite. By following the steps one should get the final result.

Flow chart is the pictorial representation of an algorithm. Flow chart uses various geometrical figures to represent the operations and arrows to show the direction of flow.

Following are the commonly used symbols in flowcharts.

flow. Following are the commonly used symbols in flowcharts. Start/stop Looping Connector Arrows to represent direction

Start/stop

Looping

Connector

Arrows to represent direction of flow

Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT Mobile No: 9985 666778 Page 6
Notes Prepared by
T. Ratna Reddy.
Associate Professor, CBIT
Mobile No: 9985 666778 Page 6
represent direction of flow Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT Mobile No: 9985

UNIT - I

UNIT - I   CH     Valid     Invalid     AR    
 

CH

   

Valid

   

Invalid

   

AR

   

AC

abhilash

 

23abc

   

TE

sum

 

_2cd

RS

product

 

P.V.N. rao

 

US

abc123

Rama rao

ED

   

IN

ab 12 cd

 

ab,cd

   

C

hyderabad (first 8 are

 

ab-cd

 

Aph

 

auto

abe

recognized)

     

ts:

Uppercase letters

A to Z

 
 

Lowercase letters

a to z

 

Numbers:

 

0 to 9

 

Special characters:

+

-

*

/

\

%

|

~ ?

!

,

.

;

:

&

#

$

^

<

>

=

(

)

[

]

{

}

_

KEY WORDS

int

float

char

double

long

short

signed

unsigned

while

do

for

break

continue

switch

case

auto

static

extern

goto

return

struct

union

if

else

sizeof

volatile

default

void

const

register

enum

Keywords serve as basic building blocks for program statements.

Each keyword has a special meaning in C.

All these keywords are in lower case letters. As capital or upper case letters and lower case letters are significant in C, all these keywords must be used in lower cases.

These key words names should not be used in function names or variable names or identifiers. Keep this list with you for reference, whenever you write programs.

No gap should be left in between the letters of a single key word, while using.

These key words are also called as reserved words or vocabulary for the language.

USER DEFINED WORDS

The words, which are defined by user, are user-defined words. They can be for variable name function name so on.

Rules of user defined words

1. It must start with an alphabet.

2. Maximum number of characters should not excess 8 (excess are ignored).

3. Second character on wards alphabets, digits or underscore’s can be used.

4. No special characters are allowed expect

underscore.

5. It cannot be a reserved word.

MEMORY CONCEPTS AND DATATYPES

Data type is defined as the type of value that can be stored in a variable EXAMPLE

int a;

Variable ‘a’ is of type int we can store only integer values in ‘a’ but not float.

float b;

Variable ‘b’ is of type float we can store only integer values in ‘a’ but not int.

we can store only integer values in ‘a’ but not int. Notes Prepared by T. Ratna
we can store only integer values in ‘a’ but not int. Notes Prepared by T. Ratna

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 7

UNIT - I

UNIT - I There are several data types in C language.   5 . double (long

There are several data types in C language.

 

5. double (long float): It takes 8B of memory

 

int

space. First 52 bits are integer part and next 12 bits are for fractional part. Decimal point is assumed

 
    after 52 th bit. It is not stored in memory. 6 .long double: It
 

after 52 th bit. It is not stored in

memory.

6.long double: It takes 10B of memory space. First 65 bits are integer part and next 15 bits are for fractional part. Decimal point is assumed after 65 th bit.

Int

long

unsigned

(2B)

(4B)

(2B)

1.int:

It takes 2B of memory space that is 16 bits. First bit

is sign bit and remaining 15 are magnitude bits.

 

char

char
 

1

010 1100 0101 0010

 

sign

magnitude

 

signed char

unsigned char

If the sign bit is zero it is +ve magnitude. If the sign bit is 1 it is -ve magnitude.

(1B)

(1B)

 

7.

unsigned char: It takes 1B of memory

Maximum integer value is 2 15 – 1 = 32767. Minimum integer value is -2 15 = -32768

space that is 8 bits. There is no sign bit, all 8 are magnitude bits. Maximum value is 2 8 – 1 = 255.minimum value is 0. Range of ASCII values is from 0 to 255

Thus integer ranges from –32768 to 32767. 2. long int: To represent a value more than 32767

long is used. It is an extension to Integer it takes 4B of memory space that is 32 bits. First bit is sign bit and remaining 31 are magnitude bits. Maximum value of long integer value is 2 31 – 1

 

8.

signed char(or) char: It takes 1B of memory

space that is 8 bits. There is one sign bit and 7 are magnitude bits are magnitude bits. Maximum value is 2 7 – 1 = 127. Minimum value is –2 7 = -128

3. unsigned int : It takes 2B of memory space that is 16 bits. There is no sign bit is sign bit. All 32 bits are magnitude bits. Maximum value unsigned integer is 2 16 – 1 = 65535. Minimum value of unsigned integer is 0.

 

Type casting

Conversion of one data type to some other data type is known as type casting. That is Conversion of int to float, float to int, int to char so on is called type casting.

We cannot represent –ve values in unsigned character

1. Implicit type casting

 

Type casting is done by system.

1.

int a = 10.8;

 

float

float
 

float value is type casted to int so a = 10, .8 is ignored.

2. float b = 25; int value is type casted to float so b = 25.0

float

double long double

(4B)

(8B)

(10B)

 

4. float : It takes 4B of memory space. First 26 bits are integer part and next 6 bits are for fractional part. Decimal point is assumed after 26 th bit. It is not stored in memory

3. char ch = 65; int value is type casted to char so that ch = A.

 

xxxxxxxx…

xxx

^ xxxxxx

4. int k = ‘z’;

 

x0 or 1

26

6

 

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 8

UNIT - I

UNIT - I character is type casted to int so k = 90. ASCII value of

character is type casted to int so k = 90. ASCII value of z.

int

%d

float

%f

 

char

%c

2. Explicit type casting.

string

%s

Type casting is done by programmer. 1. int a = 7, b = 2; printf (“%f”, (float)a/b);

Examples

1. printf(“%d”,x); to display integer value

2. printf(“%f”,a); to display float value

=

7.0/2

3. printf(“the result is %d”,x);

=

3.5

Variable a is of type, it is type casted to float so ‘a’

scanf()

Function

becomes 7.0

scanf() function is used to read/input values of variables

. The value of ‘a’ continues to be 7 in the rest of the program.

Thus type casting is not for entire a/b is 3. (float)a/b = 3.5 a/(float) b = 7/2.0 = 3.5

program

using the standard input device(keyboard).

It is an input function. It is call by address function. We must send address to scanf but not variable It has the following form

scanf(“format string”,&v1,&v2,…&vn);

 

Where v1, v2,… are variables whose values are to be

2.

float a = 9.8 , b = 5.9;

printf (“%d”, (int)a%(int)b); = 9 %5 = 4 Variables a and b of type float. They are type casted to int.

read from the keyboard.

Examples

1. scanf(“%d”,&x); to read integer value

2. scanf(“%f”,&a); to read float value

3. scanf(“%c”,&ch); to read char value

They become 9 and 5. a % b is error since %is integer operator.

So they must be type casted to int. int a; It is declaration statement. (int) a is type casting.

4. scanf(“%s”,name); to read a string

5. scanf(“%d%f”,&x,&a); to read an integer value and a float value.

Basic Input and output functions

// To find the sum of two numbers

printf()

Function

#include <stdio.h> void main()

 

print() function is used to display a string or values of

variables using the standard output device(monitor). It

{

has the following forms

int x,y,sum; printf("Enter two numbers\n"); scanf("%d%d",&x,&y); sum = x+y; printf("the sum of %d and %d is %d\n”, x,y,sum);

printf(“control string”);

printf(“control string”,v1,v2,…vn);

where v1,v2 are variables whose

values are to be displayed on the screen.

}

Control string is the format string which

represents the format specification

data type

format specifier

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 9

UNIT - I

UNIT - I S. Data Format Remark No Type specifier 1. char %c Signed character 2.

S.

Data

Format

Remark

No

Type

specifier

1.

char

%c

Signed character

2.

Int

%i

Signed integer

3.

int

%d

Signed integer in decimal number system

4.

unsigned

%o

Unsigned integer in octal number system

int

5.

unsigned

%u

Unsigned integer in decimal number system

int

6.

unsigned

%x

Unsigned integer in hexadecimal number system

int

7.

unsigned

%X

Unsigned integer in hexadecimal number system

int

8.

long int

%ld

Signed long

9.

short int

%hd

Signed short

10.

unsigned

%lu

Unsigned long

long

11.

unsigned

%hu

Unsigned short

short

12.

float

%f

Signed single precision

13.

float

%e

Signed single precision

in

e format(exponent)

14.

float

%E

Signed single precision in E format(exponent)

15.

float

%g

Signed value either in

e

or f format

16.

float

%G

Signed value either in E or F format

17.

double

%lf

Signed double

precision float

18.

string

%s

string

type

precision float 18. string %s string type Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT
precision float 18. string %s string type Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT

Notes Prepared by

T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778Page 10