CSE I-Sem)

Similar documents
Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

A flow chart is a graphical or symbolic representation of a process.

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Operators. Java operators are classified into three categories:

Chapter 3: Operators, Expressions and Type Conversion

SECTION II: LANGUAGE BASICS

DEPARTMENT OF MATHS, MJ COLLEGE

Lecture 3 Tao Wang 1

JAVA OPERATORS GENERAL

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Operators in C. Staff Incharge: S.Sasirekha

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Bit Manipulation in C

UNIT- 3 Introduction to C++

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Chapter 4. Operations on Data

LAB A Translating Data to Binary

CS33 Project Gear Up. Data

Beginning C Programming for Engineers

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Review of the C Programming Language for Principles of Operating Systems

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Arithmetic Operations

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Information Science 1

CT 229. Java Syntax 26/09/2006 CT229

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

4. Inputting data or messages to a function is called passing data to the function.

ARM Microcontroller Course

Operators & Expressions

Department of Computer Science

Computer Programming CS F111

Arithmetic Operators. Portability: Printing Numbers

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:


Computer Organization & Systems Exam I Example Questions

Logical and Bitwise Expressions

Operators in java Operator operands.

Review of the C Programming Language

Assist. Prof. Dr. Caner ÖZCAN

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Fundamentals of Programming

ISA 563 : Fundamentals of Systems Programming

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Unit 3. Operators. School of Science and Technology INTRODUCTION

Expressions and Precedence. Last updated 12/10/18

Changelog. Changes made in this version not seen in first lecture: 12 September 2017: slide 28, 33: quote solution that uses z correctly

Fundamental of Programming (C)

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Data III & Integers I

Chapter. Computer Architecture

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

CSE 230 Intermediate Programming in C and C++

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

ECE260: Fundamentals of Computer Engineering

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

BCA-105 C Language What is C? History of C

Bitwise Operators Objects and Methods

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Expressions and Assignment Statements

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

AGENDA Binary Operations CS 3330 Samira Khan

Language Reference Manual simplicity

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

Shift and Rotate Instructions

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

Bitwise Data Manipulation. Bitwise operations More on integers

PYTHON- AN INNOVATION

C Programming Language (Chapter 2 of K&R) Variables and Constants

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Ch. 3: The C in C++ - Continued -

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

ECE260: Fundamentals of Computer Engineering

Data III & Integers I

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)


Arithmetic and Bitwise Operations on Binary Data

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

Bitwise Operator and Typecasting

Bits, Bytes, and Integers

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

ECEN 468 Advanced Logic Design

Expressions. Operands. Operators

Structures, Operators

Introduction to Digital VLSI Design מבוא לתכנון VLSI ספרתי

More Programming Constructs -- Introduction

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

.Net Technologies. Components of.net Framework

Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

C expressions. (Reek, Ch. 5) 1 CS 3090: Safety Critical Programming in C

Transcription:

Objective: Understanding miscellaneous aspects of C ENUMERATED, STRUCTURE AND UNION TYPES: Derived types- structures declaration, definition and initialization of structures, accessing structures, nested structures, arrays of structures, structures and functions, pointers to structures, self referential structures, unions, typedef, bit-fields, program applications BIT-WISE OPERATORS: logical, shift, rotation, masks. C Programming Bitwise Operators: Bitwise operators are the operators which are used to perform operations at bit level. Bit Level Operations means the operations performed on individual bits of a given data. 1. Sometimes it become mandatory to consider data at bit level. 2. We have to operate on the individual data bit. We also need to turn on/off particular data bit during source code drafting, at that time we must use bitwise operator for doing our task easier. 3. C Programming provides us different bitwise operators for manipulation of bits. 4. Bitwise operators operates on Integer, character but not on float, double 5. Using bitwise operators we can manipulate individual bits easily C programming supports 6 bitwise operators Operator Name of Operator ~ Not operator (or) One s Compliment >> Right Shift << Left Shift & Bitwise AND Bitwise OR ^ Bitwise XOR Bitwise operator rules Input Bits AND OR XOR 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 Page 1 of 5

Bitwise Operators : AND,OR,XOR AND,OR,XOR are three main Bitwise Operators in C Programming Language Example : Consider two numbers 12 and 10 a = 12 b = 10 a in Binary : 0000 0000 0000 1100 (means 12) b in Binary : 0000 0000 0000 1010 (means 10) a b : 0000 0000 0000 1110 a& b : 0000 0000 0000 1000 a ^ b : 0000 0000 0000 0110 Rules from above table : 1. If Two bits are same Then Resultant XOR is 0. 2. If Two bits are different Then Resultant XOR is 1. 3. If any of the bit is 1 then Resultant OR is 1 4. If both bits are 0 then Resultant OR is 0 5. If any of the bit is 0 then Resultant AND is 0. a b : 0000 0000 0000 1110 = 14 a& b : 0000 0000 0000 1000 = 8 a ^ b : 0000 0000 0000 0110 = 6 Example : Bitwise Operator (AND,OR,XOR) int a=12,b=10; printf("\nnumber1 AND Number2 : %d",a& b); printf("\nnumber OR Number2 : %d",a b); printf("\nnumber XOR Number2 : %d",a ^ b); Number1 AND Number2 : 8 Number OR Number2 : 14 Number XOR Number2 : 6 Page 2 of 5

Not (or)one s Compliment Operator in C 1. It is denoted by ~ 2. Bit Pattern of the data can be Reversed using One s Compliment 3. It inverts each bit of operand. One s Compliment is Unary Operand i.e Operates on 1 Argument One scompliment 1111 1111 1100 0011 Zero s Are Changed to 1 One s Are Changed to 0 Syntax : ~Variable_Name Live Example : Negation Operator in C Programming int a=10; printf("\nnegation of Number 1 : %d",~a); Negation of Number 1 : -11 Page 3 of 5

Bitwise Right Shift Operator in C It is denoted by >> Bit Pattern of the data can be shifted by specified number of Positions to Right When Data is Shifted Right, leading zero s are filled with zero. Right Shift by 2 0000 0000 0000 1111 Leading 2 Blanks Replaced by 0 Syntax : [variable]>>[number of places] int a = 10; printf("\nnumber is Shifted By 1 Bit : %d",a>> 1); printf("\nnumber is Shifted By 2 Bits : %d",a>> 2); Number is Shifted By 1 Bit : 5 Number is Shifted By 2 Bits : 2 Explanation: We know the binary representation of the 10 is as below 0000 0000 0000 1010 Now after shifting all the bits to left towards MSB we will get following bit pattern 0000 0000 0000 0101 = 5 For >> 1 ------------------- 0000 0000 0000 0010 = 2 For <<2 Page 4 of 5

Bitwise Left Shift Operator in C It is denoted by << Bit Pattern of the data can be shifted by specified number of Positions to Left When Data is Shifted Left, trailing zero s are filled with zero. Left Shift 0000 0000 1111 0000 Trailing Zero s Replaced by 0 (Shown in RED) Syntax : Bitwise Left Shift Operator [variable]<<[number of places] int a = 10; printf("\nnumber is Shifted By 1 Bit : %d",a<< 1); printf("\nnumber is Shifted By 2 Bits : %d",a<< 2); Number is Shifted By 1 Bit : 20 Number is Shifted By 2 Bits : 40 Explanation: We know the binary representation of the 10 is as below 0000 0000 0000 1010 Now after shifting all the bits to left towards MSB we will get following bit pattern 0000 0000 0001 0100 = 20 For << 1 ------------------- 0000 0000 0010 1000 = 40 For <<2 Page 5 of 5