Bits and Bytes. Bit Operators in C/C++

Size: px
Start display at page:

Download "Bits and Bytes. Bit Operators in C/C++"

Transcription

1 Bits and Bytes The byte is generally the smallest item of storage that is directly accessible in modern computers, and symbiotically the byte is the smallest item of storage used by modern programming languages. We could think of the byte as the atomic level of data. But there is a subatomic story. A byte consists of eight bits, where a bit is the electronic equivalent of a bivalent entity. In other words, a bit is capable of being in exactly two states. We can think of these two states as true/false, +1/-1, or 1/0. The machine has electronic representations of bits, in groups of eight, and makes these groups of eight bits directly accessible as bytes. A byte, being the atomic data type, is the space used to store char data. You learn a lot more about this in our course CDA 3100 Computer Organization I. One of the many legacies of C, inherited by C++, is an ability to access subatomic data, data at the bit level, indirectly through bit operators. Moreover, all modern general-purpose computers have hardware support for these bit operators, which makes them extremely fast. Many C programmers use bit operators to implement various bitlevel access utilities, the most popular being the bitvector. The C++ class allows us to descend to the bit level carefully and then encapsulate this sub-atomic programming behind a public interface. We will illustrate this entire process later in the chapter by constructing a bitvector class, a class that stores and retrieves vectors of bivalent values at the bit level. The byte can store any eight-digit unsigned binary number (the binary digits are usually called bits). The range of such numbers begins with 0 (10) = (2) and ends with (2) = 255 (10). Here is the range of numbers representable in one byte, expressed in various notations: Name Base 1-Byte Range Binary Octal Decimal Hexadecimal FF The hexadecimal, or hex, representation is perhaps the most convenient to use for byte values, since it consists of exactly two hex digits. The hex digits are A B C D E F and the range of two-digit hex numbers corresponds to the decimal range = For further reading, see Number Systems, Appendix C of Dietel. Bit Operators in C/C++ The following table summarizes the bit operators C++ inherits from C: operation symbol type infix version accumulator version and & binary z = x & y z &= y or binary z = x y z = y xor ^ binary z = x ^ y z ^= y not ~ unary z = ~y (na) left shift << binary z = y << n (na) right shift >> binary z = y >> n (na) The first four bit operators listed in the table are based on the AND, OR, XOR, and NOT operators for single bits, given by the following tables: AND x y x&y OR x y x y XOR x y x^y NOT x ~x /9

2 Such tables are often called truth tables, a term from symbolic logic for the table of truth values of a logical expression based on truth/falsity of the variables in the expression. This is one of the areas where logic, math, electrical engineering, and computer architecture intersect. The table represents: (1) all possible values of a logical expression (logic), (2) a table of values for a binary function (math), (3) a table of electrical charge input/output for a circuit (electrical engineering), and (4) a basic component of a digital computer (computer architecture). In the modern computer, these bit-level operations have one-clock-cycle hardware implementations. The C/C++ bit operators &,, ^, and ~ are defined for any integral type (such as char, short, size_t, and long) by applying the single-bit operations bitwise. In other words, these operators simply apply the single-bit operations in parallel for each bit of the operand. The parallel application of the single-bit operations is also supported by hardware, so that the bitwise operators also operate in one clock cycle -- fast. The other two bit operators shown are the left shift (operator << ()) and right shift (operator >> ()). These twoargument operators take an integral type as the left operand and a non-negative integer as the right operand, and return the same integral type as the left operand. The prototypes for the shift of unsigned long, for example, are: unsigned long operator << (unsigned long, int); unsigned long operator >> (unsigned long, int); The shift operators move the bits of the left argument the number of times given by the right argument and return the (shifted) left argument as a value. Bits that are shifted out of the left operand are lost (it is said that these bits go into the "bit bucket") and bits uncovered by shifting are replaced by bit 0. Left and right shift also have hardware support, so that they execute much more quickly than standard arithmetic operators. Notes: 1. A point not to be confused over is the term "binary" as it is often applied to operators. A binary operator is an operator that takes two arguments. Similarly, a unary operator is an operator that takes only one argument. In this usage, the term "binary" is referring to the number of arguments, not their type. 2. Left shift <<() and right shift >>() are native C/C++ operators. The C++ input and output operators are overloads of these natives of C. 3. Shift operators are generally recommended only for unsigned integer types. Some shift operator behaviors on signed type are machine dependent, making their use unpredictable. 4. The shift operators are undefined when the right argument is negative or is larger than the number of bits in the binary representation of the first argument. Examples of Bit Operator Calculations This table shows some examples of bit operations in action. value of x value of y statement value of z z = x << y z = x >> y z = x & y z = x & y z = x y z = x y z = x ^ y (na) z = ~x You should be able to perform such calculations yourself. Some practice might be called for to ensure this. Defining Class BitVector Our goal in the remainder of this chapter is the development of a bit vector class, which we will call BitVector. Following the established pattern, we need a public interface and an implementation plan. BitVector Public Interface There are not that many things one can do to a bit: a bit can be set (meaning give it the value 1) or unset (meaning 2/9

3 give it the value 0); and one can flip a bit, (meaning change its value from 0 to 1 or from 1 to 0). An ability to test the value of a bit is necessary if access is to be useful. The return value of a test needs to be an integer type, which we will interpret as a bit value. These four functions form the core of the user interface for our BitVector class. namespace fsu public: void Set (size_t index); // make index bit = 1 void Unset (size_t index); // make index bit = 0 void Flip (size_t index); // change index bit int Test (size_t index) const; // return index bit value ; // // namespace fsu Note that we have placed the BitVector class in the namespace fsu. The public interface should also include constructors, a destructor, assignment operator, and a method Size() which is intended to return the number of bits stored in a BitVector object. (Due to implementation details, the unsigned integer Size() will always be a multiple of eight.) A design decision (that could be reversed later, without harm to existing client programs) is that will not have a default constructor: The size requirement (number of bits) of a BitVector object must be known in advance and passed to the constructor as a parameter. public: explicit BitVector (size_t); // construct a BitVector with specified size BitVector (const BitVector&); // copy constructor ~BitVector (); // destructor BitVector& operator = (const BitVector& a); // assignment operator size_t Size () const; // return size of bitvector ; We will also overload the Set(), Unset(), and Flip() methods so that they apply to the entire BitVector object when invoked without an index parameter: public: void Set (); // make all bits = 1 void Unset (); // make all bits = 0 void Flip (); // change all bits ; These components are collected into a summary at the end of this chapter. BitVector Implementation Plan The implementation plan for BitVector is clever, embodying many of the bit manipulation tricks invented and used by C programmers over the years. Don't feel inadequate if you didn't immediately conceive a good implementation plan. But be certain you understand the plan, as well as the details of the implementation itself. You will need to demonstrate and use this knowledge several times in this course as well as in succeeding courses and your professional life. The basic storage facility for bits will be a vector of bytes. A vector of n bytes contains 8n bits (hence the size of a BitVector object is a multiple of 8). The challenge is to index and access at the bit level. The math of this is fairly straightforward: to get to the index k bit, we divide k by 8 to get the byte and then count up to the bit in that byte corresponding to the remainder. Here is an example: Suppose we have a array v of bytes and we want the 29th bit. There are 8 bits in v[0], 8 bits in v[1], and so on. 3/9

4 Indexing these bits (beginning with index 0), bits 0 through 7 are in byte v[0], bits 8 through 15 are in byte v[1], bits 16 through 23 are in v[2], and bits 24 through 31 are in v[3]. Therefore, bit 29 is bit 5 in v[3]. Note that 29/8 = 3 (the byte number) and 29%8 = 5 (the bit number). To get to the bit with index k, we first divide k by 8 (integer division) obtaining a quotient q and remainder r. (That is, k = 8*q + r.) Then bit[k] is the rth bit of the qth byte, i.e., bit r of v[q]. We have now reduced the challenge to two problems: 1. Find the bytearray_ index for bit index k (the quotient) 2. Access the bit for bit-index k (the remainder) Problem 1 is essentially solved, just return the value k/8. To solve problem 2 we must finally "byte the bullet" and do some subatomic programming using the concept of mask. The Mask A mask for a pattern of bit locations in an integral type is a word of that type whose binary representation has bit 1 in the specified locations and bit 0 elsewhere. For our purposes here, we may as well assume the type is char, so that a word consists of a single byte, or eight bits. (Alternative approaches replace bytes with 32-bit words, and use masks for unsigned long, a 32-bit word.) Assuming type char, there are eight possible 1-bit masks, as follows: = << 0 // == 1 == 0x = << 1 // == 2 == 0x = << 2 // == 4 == 0x = << 3 // == 8 == 0x = << 4 // == 16 == 0x = << 5 // == 32 == 0x = << 6 // == 64 == 0x = << 7 // == 128 == 0x80 Notice that each of these can be obtained from (2) = 1 (10) = 0x01 (16) by applying the left shift operator, as indicated in the list above. (The decimal and hexadecimal representations of the mask are also shown above.) A mask can be used to access an individual bit of a byte. Suppose, for example, that we want to access the third bit from the right of byte x. Calculate the value y = 4 & x = & x Note that y can have only two values: = 4, or = 0. The test (y!= 0) and the third bit of x have essentially the same value, true or false. In effect, the value of the third bit (bit index 2, relative to the byte) of x is equal to the value returned by the boolean expression (((1 << 2) & x)!= 0). The mask (1 << 2) allows us to access the bit value indirectly using a test. The access is also very fast, because all of the operations have direct hardware support. We have now solved problem 2. To access bit index k, we use Mask = 1 << (index % 8) applied to the byte bytearray_[bytenumber (index)]. This completes the implementation plan for BitVector. The following private section of the BitVector class facilitates this implementation plan: private: // data unsigned char * bytearray_; size_t bytearraysize_; ; // methods size_t ByteNumber (size_t indx) const; unsigned char Mask (size_t indx) const; The two private methods ByteNumber() and Mask() capture the two main ideas for locating a particular bit in the bit vector. 4/9

5 Implementing BitVector Implementations of the BitVector member functions are not lengthy, and for the most part are straightforward applications of the ideas expressed above combined with appropriate use of the bit operators discussed earlier. Exceptions are the two private methods, whose implementations use clever ideas for optimizing the computations that make them a "bit" difficult to comprehend. (This is one good reason for building the BitVector class, so that these precious details can be committed to computer, rather than human, memory.) Class Definition Here for reference is the complete class definition: public: explicit BitVector (size_t); // construct a BitVector with specified size BitVector (const BitVector&); // copy constructor ~BitVector (); // destructor BitVector& operator = (const BitVector& a); // assignment operator size_t Size () const; // return size of bitvector void Set (size_t index); // make index bit = 1 void Set (); // make all bits = 1 void Unset (size_t index); // make index bit = 0 void Unset (); // make all bits = 0 void Flip (size_t index); // flip index bit (change value of bit) void Flip (); // flip all bits int Test (size_t index) const; // return index bit value private: // data unsigned char * bytearray_; size_t bytearraysize_; ; // methods size_t ByteNumber (size_t indx) const; static unsigned char Mask (size_t indx) const; BitVector::ByteNumber The implementation of ByteNumber() is a good example of "clever". We have already established that the private method ByteNumber(index) should return index/8, but the code below seems to return something different: index >> 3. This is actually an optimization that executes faster while accomplishing the same result. The critical observation is that 8 = 2 3, and for powers of 2 the right shift operator achieves the same result as integer division: each right shift has the same effect as division by 2, so right shifting 3 is the same as division by 8. (The reader should verify this using pencil and paper.) But, because right shift has hardware support, it is much faster than integer division, hence, the optimization. size_t BitVector::ByteNumber (size_t index) const // return index / 8 // shift right 3 is equivalent to, and faster than, dividing by 8 index = index >> 3; if (index >= bytearraysize_) std::cerr << "** BitVector error: index out of range\n"; exit (EXIT_FAILURE); return index; BitVector::Mask 5/9

6 A similarly clever trick is used in to implement the Mask method. This time, the observation is that the remainder when dividing a number by a power k of 2 is equal to the last k bits of the number in binary representation. (These are the bits that are lost to the bit bucket during the right shift by k.) Thus, the remainder when dividing by 8 is just the last 3 bits of the number, which we can access by bitwise AND with a mask of 7 = 0x07 = Again, using the mask and the AND operator is much faster than division because of the hardware support for the bit operators. Then, we shift = 0x01 = 1 by that amount to have the mask for index. unsigned char BitVector::Mask (size_t index) const // return mask for index % 8 // the low order 3 bits is the remainder when dividing by 8 size_t shiftamount = index & 0x07; // low order 3 bits return 0x01 << shiftamount; Note:The Mask method is declared as static. The connotation is that the method does not use any (non-static) class variables. It is good software engineering practice to declare any method that does not need access to objectlevel variables static. This results in improved compiler optimizations and provides protection against inadvertant access to object data in the implementation of the method. Here is a picture of the bitvector, layed out with the bytevector elements right to left so that the order of the bits increases from right to left (like a number): i = b = v = ******** ******** ******** ******** ******** ******** where i = bit index (showing only the first digit of i) b = byte number (aka bytevector index) v = bytearray (spaces just for readability) So for example if i = 19 then i = 19 b = 19/8 = 2 and m = (0x01 << 19%8) = (0x01 << 3) = , and the specific picture is: b = v = ******** ******** ******** ****x*** ******** ******** i = 1 m = In words: bit 19 is in the array element 2 and has mask Note that mask & v[2] = 0000x000: the byte 0000x000 is zero iff the bit x is zero, which is the way Test(i) is implemented: Test(11) = 1 if x = one and Test(11) = 0 if x = zero Thus we have a way of detecting the value of bit 11 without having direct access to it. BitVector Constructor The constructor takes a size parameter and calls operator new unsigned char with parameter equal to the integer that is just larger or equal to numbits/8. BitVector::BitVector (size_t numbits) // constructor bytearraysize_ = (numbits + 7)/8; bytearray_ = new unsigned char [bytearraysize_]; if (bytearray_ == 0) std::cerr << "** BitVector memory allocation failure -- terminating program.\n"; exit (EXIT_FAILURE); for (size_t i = 0; i < bytearraysize_; ++i) bytearray_[i] = 0x00; 6/9

7 BitVector Assignment Operator The assignment operator follows the typical pattern: BitVector& BitVector::operator = (const BitVector& bv) // assignment operator if (this!= &bv) if (bytearraysize_!= bv.bytearraysize_) delete [] bytearray_; bytearraysize_ = bv.bytearraysize_; bytearray_ = new unsigned char [bytearraysize_]; if (bytearray_ == 0) std::cerr << "** BitVector memory allocation failure -- terminating program.\n"; exit (EXIT_FAILURE); for (size_t i = 0; i < bytearraysize_; ++i) bytearray_[i] = bv.bytearray_[i]; return *this; BitVector API The BitVector API consists of the public methods Set, Unset, Flip, and Test (two versions of each of the first three). The Test(index) method, like the remaining methods taking an index parameter, is a one-liner. But the line isclever. The idea is to isolate the indexed bit with a mask and test for non-zero result, as we established earlier. Look carefully at the computation shown and be certain you understand it. int BitVector::Test (size_t index) const // return specified bit value return 0!= (bytearray_[bytenumber(index)] & Mask(index)); Our final example is the Set(index) method, another one-liner: void BitVector::Set (size_t index) // set specified bit bytearray_[bytenumber(index)] = Mask(index); The rest of the implementation of BitVector is left as an assignment. Enjoy. Sample BitVector Client Appended below is source code for a straightforward functionality test client for BitVector. Here are some key attributes of the program: The program allows the user to set the bitvector size at the beginning of the test. To allow the user to set the bitvector size, dynamic allocation must be used (operators new and delete). The user is presented a simple interface that gives access to most of the public interface of BitVector. Assignment and copy constructor are not tested by this program. The test client can also be used as a device to discover by experiment how bitvectors behave. An executable of this client may be accessed in area51. If you want to get the feel of bitvector use, give this a try. Copy the executable into your directory and run it by typing the name. 7/9

8 /* fbitvect.cpp */ testing BitVector #include <xbitvect.cpp> void display_menu(unsigned int size); int main() char selection; size_t size, index; std::cout << "Welcome to fbitvect. Enter size of BitVector: "; std::cin >> size; fsu::bitvector * bvptr = new fsu::bitvector (size); display_menu(size); do std::cout << " Enter [op][index] (m for menu, x to exit): "; std::cin >> selection; switch(selection) case 'S': bvptr->set(); case 'U': bvptr->unset(); case 'F': bvptr->flip(); case 's': std::cin >> index; bvptr->set(index); case 'u': std::cin >> index; bvptr->unset(index); case 'f': std::cin >> index; bvptr->flip(index); case 't': case 'T': std::cin >> index; std::cout << " v[" << index << "] == "; if (bvptr->test(index)) std::cout << "1\n"; else std::cout << "0\n"; case 'd': case 'D': std::cout << " v == " << *bvptr << '\n'; case 'm': case 'M': display_menu(size); case 'x': case 'X': default: std::cout << " command not found\n"; while (selection!= 'x' && selection!= 'X'); delete bvptr; std::cout << "Thank you for testing BitVector\n"; return 0; void display_menu(unsigned int size) 8/9

9 std::cout << " BitVector (" << size << ") v;\n" << " operation entry\n" << " \n" << " v.set (). S\n" << " v.set (index).. s\n" << " v.unset (). U\n" << " v.unset (index).. u\n" << " v.flip (). F\n" << " v.flip (index).. f\n" << " v.test (index).. t\n" << " cout << v.. d\n" << " display this Menu m\n" << " exit program.. x\n"; This harness does not test the copy constructor and assignment operator. To expand the program to include test of the assignment operator would require defining three bitvector objects (instead of one as above) and adding for each of these objects all of the options above plus assignment plus three-way assignment. A function call (passing a bitvector by value) and return would be a good test of the copy constructor. 9/9

LAB A Translating Data to Binary

LAB A Translating Data to Binary LAB A Translating Data to Binary Create a directory for this lab and perform in it the following groups of tasks: LabA1.java 1. Write the Java app LabA1 that takes an int via a command-line argument args[0]

More information

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n Static and Dynamic Memory Allocation In this chapter we review the concepts of array and pointer and the use of the bracket operator for both arrays and pointers. We also review (or introduce) pointer

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

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

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

More information

Chapter 4. Operations on Data

Chapter 4. Operations on Data Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations

More information

Logical and Bitwise Expressions

Logical and Bitwise Expressions Logical and Bitwise Expressions The truth value will set you free. 1 Expression Constant Variable Unary Operator Binary Operator (expression) Function Invocation Assignment: = Prefix: +, -, ++, --,!, ~

More information

Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University

Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University Review of Data Representation & Binary Operations Dhananjai M. Rao () CSA Department Miami University 1. Introduction In digital computers all data including numbers, characters, and strings are ultimately

More information

Logical and Bitwise Expressions

Logical and Bitwise Expressions Logical and Bitwise Expressions The truth value will set you free. 1 C Numbers and Logic Logic deals with two values: True and False Numbers have many values In C, zero is interpreted as logically False

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

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

A flow chart is a graphical or symbolic representation of a process. Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

More information

Variables and numeric types

Variables and numeric types s s and numeric types Comp Sci 1570 to C++ types Outline s types 1 2 s 3 4 types 5 6 Outline s types 1 2 s 3 4 types 5 6 s types Most programs need to manipulate data: input values, output values, store

More information

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

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

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 Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

More information

Binary Values. CSE 410 Lecture 02

Binary Values. CSE 410 Lecture 02 Binary Values CSE 410 Lecture 02 Lecture Outline Binary Decimal, Binary, and Hexadecimal Integers Why Place Value Representation Boolean Algebra 2 First: Why Binary? Electronic implementation Easy to store

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.1 Unit 2 Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Perform addition & subtraction

More information

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003 Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

More information

A Java program contains at least one class definition.

A Java program contains at least one class definition. Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Beginning C Programming for Engineers

Beginning C Programming for Engineers Beginning Programming for Engineers R. Lindsay Todd Lecture 6: Bit Operations R. Lindsay Todd () Beginning Programming for Engineers Beg 6 1 / 32 Outline Outline 1 Place Value Octal Hexadecimal Binary

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 2400: Computer Architecture ECE 3217: Computer Architecture and Organization Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides

More information

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

C Programming Language (Chapter 2 of K&R) Variables and Constants C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;

More information

CS 241 Data Organization Binary

CS 241 Data Organization Binary CS 241 Data Organization Binary Brooke Chenoweth University of New Mexico Fall 2017 Combinations and Permutations In English we use the word combination loosely, without thinking if the order of things

More information

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10

More information

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Expressions and Operators in C (Partially a Review) Expressions are Used

More information

Lecture 17 Bit Operations

Lecture 17 Bit Operations Lecture 17 Bit Operations In this lecture Background Left Shifting Negative Numbers, one s complement and two s complement Right Shifting Bit Operators Masking the Bits Getting the Bits Setting the Bits

More information

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Website is up

More information

CPS122 Lecture: From Python to Java

CPS122 Lecture: From Python to Java Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

Memory Addressing, Binary, and Hexadecimal Review

Memory Addressing, Binary, and Hexadecimal Review C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend

More information

Number Systems. Both numbers are positive

Number Systems. Both numbers are positive Number Systems Range of Numbers and Overflow When arithmetic operation such as Addition, Subtraction, Multiplication and Division are performed on numbers the results generated may exceed the range of

More information

CS112 Lecture: Primitive Types, Operators, Strings

CS112 Lecture: Primitive Types, Operators, Strings CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive

More information

Applied Computer Programming

Applied Computer Programming Applied Computer Programming Representation of Numbers. Bitwise Operators Course 07 Lect.eng. Adriana ALBU, PhD Politehnica University Timisoara Internal representation All data, of any type, processed

More information

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

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

Programming. Elementary Concepts

Programming. Elementary Concepts Programming Elementary Concepts Summary } C Language Basic Concepts } Comments, Preprocessor, Main } Key Definitions } Datatypes } Variables } Constants } Operators } Conditional expressions } Type conversions

More information

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1 CS61B Lecture #14: Integers Last modified: Wed Sep 27 15:44:05 2017 CS61B: Lecture #14 1 Integer Types and Literals Type Bits Signed? Literals byte 8 Yes Cast from int: (byte) 3 short 16 Yes None. Cast

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

... IntArray B (100); // IntArray with 100 elements, each initialized to 0

... IntArray B (100); // IntArray with 100 elements, each initialized to 0 Types with External Resources A class constructor is invoked when an object comes into scope. The constructor prepares the object by creating an environment in which the member functions operate. For many

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

More information

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We

More information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning 4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

More information

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz) SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:

More information

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below: QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

More information

Chapter 9. Operator Overloading. Dr Ahmed Rafat

Chapter 9. Operator Overloading. Dr Ahmed Rafat Chapter 9 Operator Overloading Overloading Operators Overloading Basics How Operators are Overloaded Arithmetic Operators Fstring Class Example Cast Operator Equality and Relational Operators Bitwise Operators

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

ME 461 C review Session Fall 2009 S. Keres

ME 461 C review Session Fall 2009 S. Keres ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help

More information

AGENDA Binary Operations CS 3330 Samira Khan

AGENDA Binary Operations CS 3330 Samira Khan AGENDA Binary Operations CS 3330 Logistics Review from last Lecture Samira Khan University of Virginia Jan 31, 2017 Binary Operations Logical Operations Bitwise Operations Examples 2 Feedbacks Quizzes

More information

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

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for

More information

Workbook 2. Remember to check the course website regularly for announcements and errata:

Workbook 2. Remember to check the course website regularly for announcements and errata: Introduction Workbook 2 In this workbook you will explore the basic types used for storing data in Java. You will also make use of the associated functions or operators. In the assessed exercise, you will

More information

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

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

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 1 CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Number Representation Hindu-Arabic numerals developed by Hindus starting in

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction CS106L Spring 2009 Handout #21 May 12, 2009 static Introduction Most of the time, you'll design classes so that any two instances of that class are independent. That is, if you have two objects one and

More information

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997 Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997 APPENDIX A.1 Number systems and codes Since ten-fingered humans are addicted to the decimal system, and since computers

More information

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

Number System. Introduction. Decimal Numbers

Number System. Introduction. Decimal Numbers Number System Introduction Number systems provide the basis for all operations in information processing systems. In a number system the information is divided into a group of symbols; for example, 26

More information

Lab # 02. Basic Elements of C++ _ Part1

Lab # 02. Basic Elements of C++ _ Part1 Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special

More information

SIGNED AND UNSIGNED SYSTEMS

SIGNED AND UNSIGNED SYSTEMS EE 357 Unit 1 Fixed Point Systems and Arithmetic Learning Objectives Understand the size and systems used by the underlying HW when a variable is declared in a SW program Understand and be able to find

More information

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

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

More information

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

PART I.   Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++. Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

Computer Programming C++ (wg) CCOs

Computer Programming C++ (wg) CCOs Computer Programming C++ (wg) CCOs I. The student will analyze the different systems, and languages of the computer. (SM 1.4, 3.1, 3.4, 3.6) II. The student will write, compile, link and run a simple C++

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems SCHOOL OF ENGINEERING & BUILT ENVIRONMENT Mathematics Numbers & Number Systems Introduction Numbers and Their Properties Multiples and Factors The Division Algorithm Prime and Composite Numbers Prime Factors

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

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

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is

More information

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

More information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Embedded Systems - FS 2018

Embedded Systems - FS 2018 Institut für Technische Informatik und Kommunikationsnetze Prof. L. Thiele Embedded Systems - FS 2018 Lab 0 Date : 28.2.2018 Prelab Filling the gaps Goals of this Lab You are expected to be already familiar

More information

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

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one. http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

More information

COMP322 - Introduction to C++ Lecture 01 - Introduction

COMP322 - Introduction to C++ Lecture 01 - Introduction COMP322 - Introduction to C++ Lecture 01 - Introduction Robert D. Vincent School of Computer Science 6 January 2010 What this course is Crash course in C++ Only 14 lectures Single-credit course What this

More information

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng Slide Set 1 for ENEL 339 Fall 2014 Lecture Section 02 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2014 ENEL 353 F14 Section

More information

Operator overloading

Operator overloading 1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Boolean Algebra Developed by

More information

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning 4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

More information

Course Outline Introduction to C-Programming

Course Outline Introduction to C-Programming ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators. Portability: Printing Numbers Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

More information

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

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

More information

Arithmetic Processing

Arithmetic Processing CS/EE 5830/6830 VLSI ARCHITECTURE Chapter 1 Basic Number Representations and Arithmetic Algorithms Arithmetic Processing AP = (operands, operation, results, conditions, singularities) Operands are: Set

More information