AN EXAMPLE FOR THE USE OF BITWISE OPERATIONS IN PROGRAMMING. Krasimir Yordzhev
|
|
- Garry Williamson
- 6 years ago
- Views:
Transcription
1 МАТЕМАТИКА И МАТЕМАТИЧЕСКО ОБРАЗОВАНИЕ, 2009 MATHEMATICS AND EDUCATION IN MATHEMATICS, 2009 Proceedings of the Thirty Eighth Spring Conference of the Union of Bulgarian Mathematicians Borovetz, April 1 5, 2009 AN EXAMPLE FOR THE USE OF BITWISE OPERATIONS IN PROGRAMMING Krasimir Yordzhev This piece of work presents a meaningful example for the advantages of using bitwise operations for creating effective algorithms in programming. A task connected with mathematic modeling in weaving industry is examined and computed. 1. Introduction. The use of bitwise operations is a powerful method provided by C/C++ programming languages. Unfortunately in widespread books on this topic there is incomplete or no description for the work of the bitwise operations [2, 4, 5, 9, 11]. The aim of the article is to correct this lapse to a certain extent and present a meaningful example of a programming problem, where the use of bitwise operations is appropriate in order to facilitate the work and to increase the effectiveness of the respective algorithm. On the other hand the algorithm specified here could have a good practical application for computing a known combinatorial task connected with the classification of the various textile structures. 2. Problem formulation. Let us denote by Bn the set of all n n binary matrices, i.е. matrices composed by n rows and n columns, all elements of which are either 0 or 1. It is a well-known fact that the number of all matrices of Bn is equal to 2 n2. Let A, B Bn. We will say, that A and B are equivalent and we will write A B, if B is obtained from A as a result of sequential cyclic move of the last row or column at a first place. It is easy to see that the so described relation is an equivalence relation. In this way we come to a formulation of the following programming problem: Problem 1. Write a program for with assigned positive integer n returns one representative of each equivalence class in Bn concerning the above mentioned equivalence relation. As a result from the solution of problem 1 we will also compute a combinatorial problem to find the number of all equivalence classes in Bn regarding the equivalence relation, i.e. for finding the cardinal number of the factor set Bn /. This problem is applicable in wavering industry. With the help of the elements of Bn the various threads interweaving of a certain weaver structure could be coded, and with this coding by using two equivalent matrices the weaving of one and the same fabric is coded, because of cyclic recurrence of the repetition of interweaving [6, 8]. From a practical point of view just matrices with at least one 0 and at least one 1 in each row and each column have meaning. Let us mark with Qn the set of all matrices of that kind, Qn Bn. The next problem which we are going to compute is a bit more difficult version of problem 1. Problem 2. Write a program that for assigned positive integer n returns one representative of each equivalence class in Qn concerning the above mentioned equivalence relation. 196
2 3. Bitwise operations in C/C++. Bitwise operations can be applied for integer data type only, i.e. they cannot be used for float and double types. For the definition of the bitwise operations in C/C++ and some of their elementary applications could be seen, for example, in [1, 3, 7, 10]. We assume as usually that bits numbering in variables starts from right to left, and that the number of the very right one is 0. Let x, y and z be integer variables of one type, for which w bits are needed. Let x and y be initialized and let the assignment z = xαy is made, where α is one of the operations & (bitwise AND), (bitwise inclusive OR) or (bitwise exclusive OR). For each i = 0, 1,..., w 1 the new contents of the i bit in z will be as it is presented in the following table: The i bit The i bit The i bit of The i bit of The i bit of of x of y x&y x y x y In case that z = x, if the i bit of x is 0, then the i bit of z becomes 1, and if the i bit of x is 1, then the i bit of z becomes 0, i = 0, 1,..., w 1. In case that k is a nonnegative integer, then the statement z = x k; (bitwise shift left) will write in the (i+k) bit of z the value of the k bit of x, where i = 0, 1,..., w k 1, and the very right k bits of z will be filled by zeroes. This operation is equivalent to a multiplication of x by 2 k. The statement z = x k works in similar way (bitwise shift right). But we must be careful here, because in various programming environments (see for example in [7]) this operation has different interpretations somewhere k bits of z from the very left place are compulsory filled by 0 (logical displacement), and elsewhere the very left k bits of z are filled with the value from the very left (sign) bit; i.e. if the number is negative, then the filling will be with 1 (arithmetic displacement). Therefore it is recommended to use unsigned type of variables (if the opposite is not necessary) while working with bitwise operations. Directly from the definition of the operation bitwise shift left follows the effectiveness of the following function computing 2 k, where k is a nonnegative integer: unsigned int Power2(unsigned int k) { return 1<<k; To compute the value of the i bit of an integer variable x we can use the function: int BitValue(int x, unsigned int i) { if ( (x & (1<<i) ) == 0 ) return 0; else return 1; 197
3 Bitwise operations are left associative. The priority of operations in descending order is as follows: bitwise complement ; arithmetic operations (multiply), / (divide), % (remainder or modulus); arithmetic operations + (binary plus or add) (binary minus or subtract); the bitwise operations << and >>; relational operations <, >, <=, >=, ==,!=; bitwise operations &, and ; logical operations && and. 4. Algorithm realization. Each n n binary matrix A can be coded with the help of vector (array) of n nonnegative integers v = (v 0, v 1,..., v n 1 ), where 0 v i 2 n 1 for each i: 0 i n 1. One-to-one correspondence is realized through binary presentation of natural numbers, i.e. the i row of the matrix A is v i in binary system. The row i of A will be completely nil if and only if v i = 0; and all elements of the i row of A will be equal to 1 if and only if v i = 2 n 1. In other words, it is a necessary and sufficient condition for each i = 0, 1,..., n 1 to be realized 1 v i 2 n 2, in order to obtain at least one 0 and at least one 1 in each row. In order to obtain at least one 0 in each column of the matrix A, it is necessary and sufficient that the bitwise AND of all numbers, representing the rows of A to be equal to 0. In order to obtain at least one 1 in each column of the matrix A it is necessary and sufficient that the bitwise inclusive OR of all numbers, representing the rows of A to be equal to 2 n 1, i.e. to be equal to the number which is written in binary system with n ones. Thus we obtain the following function, which checks whether the array of n integers v = (v 0, v 1,..., v n 1 ) represents a matrix of Qn, or not int IsQn(unsigned int v[], unsigned int n) { // Returns 1, if with v a matrix in Qn is coded // Returns 0, otherwise for (int i=0; i <= n-1; i++) if (v[i]<1 $ v[i] > (1<<n)-2) return 0; int x,y; x = (1<<n) -1; y=0; for (int j=0; j <= n-1; j++) { x = x & v[j]; y = y v[j]; if (x!= 0) return 0; if (y!= (1<<n)-1) return 0; return 1; Let x be an integer, for which we are certain that it belongs to the interval 0 x 2 n 1, i.e. there is no need of more than n digits 0 or 1 for its binary code. Then to present x in binary system (see the function BitValue described in the previous section), written with the aid of exactly n digits 0 or 1 and eventually with a certain number of insignificant zeroes at the beginning, we can use the following function: 198
4 void BinPrn(int x, unsigned int k) { int z; for (int i = k-1; i >= 0; i--) { z = x & (1<<i); if (z == 0) cout<< 0 ; else cout<< 1 ; cout<< \n ; Let us examine the set V = {(v 0, v 1,..., v n 1 ) 0 v i 2 n 1, i = 0, 1,..., n 1. All elements of V can be sorted in ascending lexicographic order. The essence of the proposed by us algorithm is to obtain sequentially all elements of V in the same increasing order from the smallest one to the biggest one and right after obtaining them to check whether this element is minimal according to the lexicographic order in the class of equivalence. At last we will separate just the minimal in their class of equivalency elements and they will be the only representatives of each equivalency class in the sets Bn and Qn (which was required in Problems 1 and 2). For this purpose we will design a function IsMin, which will return 1, if the input argument is minimal in the class of equivalency to which it belongs to, and 0 otherwise. But before that we need the following auxiliary function CicleMove, which for assigned nonnegative integers x and n returns a number, which is obtained from x by moving all bits one position to the right, beginning with the moving of the very right bit to the place of the bit n 1. In this case we will be helped by the bitwise operations. unsigned int CicleMove(unsigned int x,unsigned int n) unsigned int b0 = x & 1; // Record the value //of the very right bit of x x=x & ((1<<n)-1); // Replaces all bits to the //left from the on with number (n-1) with 0 return (x >> 1)$\vert $(b0 << n-1); The following auxiliary function will also be useful for the computing of the main problem: Int IsLess(unsigned int u[],unsigned int v[],int n) { // Return 1, if according to lexicographic order //u[0] u[1] \ldots u[n-1] < v[0] v[1] \ldots v[n-1] // Return 0, otherwise int i = 0; while ((u[i] == v[i]) && (i<n-1)) i++; if (u[i] < v[i]) return 1; else return 0; 199
5 The above mentioned function IsMin could look as follows: int IsMin(unsigned int v[], unsigned int n) { // Return 1, if according to lexicographic order //v[0] v[1] \ldots v[n-1]is minimal in its class of equivalency // Return 0, otherwise unsigned int u[32], v1[32]; for (int i = 0; i <= n-1; i++) v1[i] = v[i]; for (int j = 0; j <= n-1; j++) { for (int i = 1; i <= n-1; i++) { for (int s = 0; s <= n-1; s++) { int s1 = (s+i) % n; u[s] = v1[s1]; if (IsLess(u,v,n) ) return 0; for (int i=0; i <= n-1; i++) v1[i]=ciclemove(v1[i],n); return 1; Taking the advantages of the above described functions we propose the following computing of Problems 1 and 2 (for n = 4, for example). In order to be brief here we will not print all the elements obtained, and we will obtain their numbers only. For the hard-copy itself for each row of any of the obtained matrices we can take advantage of the above described procedure BinPrn and after organizing of a cycle by the number of the row to print the whole matrix as well. int main() { const int n=4; int i; unsigned long int NBn = 0; // Number of elements in Bn unsigned long int NQn = 0; // Number of elements in Qn unsigned long int NBnEq = 0; // Number of the //classes of equivalency in Bn unsigned long int NQnEq = 0; // Number of the //classes of equivalency in Qn unsigned int v[n]; int r=(1<<n)-1; for (i = 0; i<n; i++) v[i]=0; do { i=n-1; for (int k=0; k<=r; k++) { v[i]=k; NBn++; if (IsQn(v,n) ) NQn++; if (IsMin(v,n) ) { 200
6 NBnEq++; if (IsQn(v,n)) NQnEq++; while (v[i]==r) i--; if (i>=0) { v[i]++; for (int k=n-1; k>i; k--) { v[k]=0; while ( i>=0 ); cout<<"number of elements in Bn "<<NBn<< \n ; cout<<"number of elements in Qn "<<NQn<< \n ; cout<<"number of the classes of equivalency in Bn "<<NBnEq<< \n ; cout<<"number of the classes of equivalency in Qn "<<NQnEq<< \n ; return 0; The results from the above described program for some values of n can be summarized in the following table. n Bn > Qn > Bn / Qn / REFERENCES [1] S. R. Davis C++ for dummies. IDG Books Worldwide, [2] C. S. Horstmann Computing concepts with C++ essentials. John Wiley & Sons, [3] B. W. Kernigan, D. M. Ritchie The C programming Language. AT&T Bell Laboratories, [4] П. Азълов. Информатика: Езикът С++ в примери и задачи за 9-10 клас. София, Просвета, [5] П. Азълов. Обектно ориентирано програмиране Структури от данни и STL. София, Сиела, [6] Г. И. Борзунов. Шерстяная промишленост обзорная информация. Москва, ЦНИИ ИТЭИЛП, 3, [7] С. В. Глушаков, А. В. Коваль, С. В. Смирнов. Язык программирования C++. Харьков, Фолио, [8] К. Я. Йорджев, И. В. Статулов. Математическо моделиране и количествена оценка на първичните тъкачни сплитки. Текстил и облекло, 10, (1999), [9] Х. Крушков. Практическо ръководство по програмиране на С++. Пловдив, Макрос,
7 [10] Е. Л. Романов. Практикум по программированию на C++. Санкт Петербург, БХВ, [11] М. Тодорова. Програмиране на С++. Част I, част II, София, Сиела, Krasimir Yordzhev South-West University N. Rilsky 2700 Blagoevgrad, Bulgaria ПРИМЕР ЗА ИЗПОЛЗУВАНЕ НА ПОБИТОВИ ОПЕРАЦИИ В ПРОГРАМИРАНЕТО Красимир Йорджев В работата е посочен съдържателен пример за използуването на побитовите оператори при оформянето на ефективни алгоритми в програмирането. Разгледана и решена е една задача, свързана с математическото моделиране в тъкачната промишленост. 202
An Entertaining Example for the Usage of Bitwise Operations in Programming
An Entertaining Example for the Usage of Bitwise Operations in Programming Hristina Kostadinova, Krasimir Yordzhev South-West University "Neofit Rilski" Blagoevgrad, Bulgaria kostadinova@swu.bg yordzhev@swu.bg
AN EXAMPLE FOR THE USE OF BITWISE OPERATIONS IN PROGRAMMING
AN EXAMPLE FOR THE USE OF BITWISE OPERATIONS IN PROGRAMMING Krasimir Yakov Yordzhev This piece of work presets a meaigful example for the advatages of usig bitwise operatios for creatig effective algorithms
arxiv: v1 [cs.ms] 6 Jan 2012
1 A Representation of Binary Matrices Hristina Kostadinova Krasimir Yordzhev arxiv:1201.1473v1 [cs.ms] 6 Jan 2012 Abstract In this article we discuss the presentation of a random binary matrix using sequence
A REPRESENTATION OF BINARY MATRICES * Hristina Kostadinova, Krasimir Yordzhev
МАТЕМАТИКА И МАТЕМАТИЧЕСКО ОБРАЗОВАНИЕ, 2010 MATHEMATICS AND EDUCATION IN MATHEMATICS, 2010 Proceedings of the Thirty Ninth Spring Conference of the Union of Bulgarian Mathematicians Albena, April 6 10,
arxiv: v2 [math.co] 29 May 2013
arxiv:1301.5100v2 [math.co] 29 May 2013 Bitwise operations related to a combinatorial problem on binary matrices Krasimir Yankov Yordzhev Abstract Some techniques for the use of bitwise operations are
Bitwise Operations Related to a Combinatorial Problem on Binary Matrices
I.J.Modern Education and Computer Science, 2013, 4, 19-24 Published Online May 2013 in MECS (http://www.mecs-press.org/) DOI: 10.5815/ijmecs.2013.04.03 Bitwise Operations Related to a Combinatorial Problem
REALIZATION OF OPEN ADDRESSING HASH TABLE IN THE CHAINED ALLOCATED MEMORY. Valentina Dyankova and Rositza Hristova
International Journal "Information Theories & Applications" Vol.11 381 REALIZATION OF OPEN ADDRESSING HASH TABLE IN THE CHAINED ALLOCATED MEMORY Valentina Dyankova and Rositza Hristova Abstract: In this
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.
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
ON TWO ADAPTIVE SYSTEMS FOR DOCUMENT MANAGEMENT * Vanyo G. Peychev, Ivo I. Damyanov
МАТЕМАТИКА И МАТЕМАТИЧЕСКО ОБРАЗОВАНИЕ, 2005 MATHEMATICS AND EDUCATION IN MATHEMATICS, 2005 Proceedings of the Thirty Fourth Spring Conference of the Union of Bulgarian Mathematicians Borovets, April 6
Operators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
WAREHOUSING AND OLAP ANALYSIS OF DATA ABOUT UNIQUE BULGARIAN BELLS * Tihomir Trifonov, Tsvetanka Georgieva-Trifonova
МАТЕМАТИКА И МАТЕМАТИЧЕСКО ОБРАЗОВАНИЕ, 2012 MATHEMATICS AND EDUCATION IN MATHEMATICS, 2012 Proceedings of the Forty First Spring Conference of the Union of Bulgarian Mathematicians Borovetz, April 9 12,
Power Set of a set and Relations
Power Set of a set and Relations 1 Power Set (1) Definition: The power set of a set S, denoted P(S), is the set of all subsets of S. Examples Let A={a,b,c}, P(A)={,{a},{b},{c},{a,b},{b,c},{a,c},{a,b,c}}
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
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
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
Expression and Operator
Expression and Operator Examples: Two types: Expressions and Operators 3 + 5; x; x=0; x=x+1; printf("%d",x); Function calls The expressions formed by data and operators An expression in C usually has a
COMP2611: Computer Organization. Data Representation
COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How
Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
DEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
Floating Point Arithmetic
Floating Point Arithmetic Computer Systems, Section 2.4 Abstraction Anything that is not an integer can be thought of as . e.g. 391.1356 Or can be thought of as + /
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.
A Method for Construction of Orthogonal Arrays 1
Eighth International Workshop on Optimal Codes and Related Topics July 10-14, 2017, Sofia, Bulgaria pp. 49-54 A Method for Construction of Orthogonal Arrays 1 Iliya Bouyukliev iliyab@math.bas.bg Institute
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
Programming in C++ 5. Integral data types
Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long
Chapter 4 Arithmetic Functions
Logic and Computer Design Fundamentals Chapter 4 Arithmetic Functions Charles Kime & Thomas Kaminski 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Overview Iterative combinational
Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O
Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.
Chapter 10 Error Detection and Correction 10.1
Chapter 10 Error Detection and Correction 10.1 10-1 INTRODUCTION some issues related, directly or indirectly, to error detection and correction. Topics discussed in this section: Types of Errors Redundancy
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
Some Models of a Distributed Database Management System with Data Replication
Some Models of a Distributed Database Management System with Data Replication Svetlana Vasileva, Petar Milev, Borislav Stoyanov Abstract: The article suggests a formal model of Distributed Database Management
4. Number Representations
Educational Objectives You have a good understanding how a computer represents numbers. You can transform integers in binary representation and perform computations. You understand how the value range
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
COMPUTER ARITHMETIC (Part 1)
Eastern Mediterranean University School of Computing and Technology ITEC255 Computer Organization & Architecture COMPUTER ARITHMETIC (Part 1) Introduction The two principal concerns for computer arithmetic
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
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
Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
Programming. Elementary Concepts
Programming Elementary Concepts Summary } C Language Basic Concepts } Comments, Preprocessor, Main } Key Definitions } Datatypes } Variables } Constants } Operators } Conditional expressions } Type conversions
World Inside a Computer is Binary
C Programming 1 Representation of int data World Inside a Computer is Binary C Programming 2 Decimal Number System Basic symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Radix-10 positional number system. The radix
DM and Cluster Identification Algorithm
DM and Cluster Identification Algorithm Andrew Kusiak, Professor oratory Seamans Center Iowa City, Iowa - Tel: 9-9 Fax: 9- E-mail: andrew-kusiak@uiowa.edu Homepage: http://www.icaen.uiowa.edu/~ankusiak
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
Random Permutations, Random Sudoku Matrices and Randomized Algorithms
Random Permutations, Random Sudoku Matrices and Randomized Algorithms arxiv:1312.0192v1 [math.co] 1 Dec 2013 Krasimir Yordzhev Faculty of Mathematics and Natural Sciences South-West University, Blagoevgrad,
THE MATHEMATICAL MODEL OF AN OPERATOR IN A HUMAN MACHINE SYSTEMS. PROBLEMS AND SOLUTIONS
50 І н ф о р м а ц і й н і с и с т е м и, м е х а н і к а т а к е р у в а н н я UDC 621.396 A. Kopyt THE MATHEMATICAL MODEL OF AN OPERATOR IN A HUMAN MACHINE SYSTEMS. PROBLEMS AND SOLUTIONS That s why
2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.
1. Why do you think C++ was not named ++C? C++ is a super set of language C. All the basic features of C are used in C++ in their original form C++ can be described as C+ some additional features. Therefore,
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
Arithmetic and Logic Blocks
Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation
Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)
Lecture Topics Today: Integer Arithmetic (P&H 3.1-3.4) Next: continued 1 Announcements Consulting hours Introduction to Sim Milestone #1 (due 1/26) 2 1 Overview: Integer Operations Internal representation
Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2
Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Ziad Matni Dept. of Computer Science, UCSB Adding this Class The class is full I will not be adding more ppl L Even if others
RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:
http://www.tutorialspoint.com/ruby/ruby_operators.htm RUBY OPERATORS Copyright tutorialspoint.com Ruby supports a rich set of operators, as you'd expect from a modern language. Most operators are actually
Unit-2 (Operators) ANAND KR.SRIVASTAVA
Unit-2 (Operators) ANAND KR.SRIVASTAVA 1 Operators in C ( use of operators in C ) Operators are the symbol, to perform some operation ( calculation, manipulation). Set of Operations are used in completion
Outline. 1 About the course
Outline EDAF50 C++ Programming 1. Introduction 1 About the course Sven Gestegård Robertz Computer Science, LTH 2018 2 Presentation of C++ History Introduction Data types and variables 1. Introduction 2/1
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
Informatics Ingeniería en Electrónica y Automática Industrial
Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical
In this lesson you will learn: how to add and multiply positive binary integers how to work with signed binary numbers using two s complement how fixed and floating point numbers are used to represent
CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I
CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda Everything is a Number
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: - +
CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010
CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please
«, 68, 55, 23. (, -, ).,,.,,. (workcamps).,. :.. 2
,.. 2017. 49.03.03. -,......,..... 2017 «, 68, 55, 23. (, -, ).,,.,,. (workcamps).,. :.. 2 ......4 1..6 1. 1...6 1. 2...9 1.3...14 2...20 2.1.........20 3. 22 3.1...22 3.2...34 3.3,.41.....44..... 48 A
THE COMPUTER EXPERIMENT IN SCHOOL AS A METHODOLOGICAL TOOL IN SCIENCE EDUCATION
THE COMPUTER EXPERIMENT IN SCHOOL AS A METHODOLOGICAL TOOL IN SCIENCE EDUCATION Grozdev S. 1, Ismailov Sh. 2 1 Mathematics and Informatics Institute BAN, Sofia, Republic of Bulgaria 2 Tashkent Region State
Ch. 7 Error Detection and Correction
Ch. 7 Error Detection and Correction Error Detection and Correction Data can be corrupted during transmission. Some applications require that errors be detected and corrected. 2 1. Introduction Let us
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
Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C
Mechatronics and Microcontrollers Szilárd Aradi PhD Refresh of C About the C programming language The C programming language is developed by Dennis M Ritchie in the beginning of the 70s One of the most
CS 253. January 14, 2017
CS 253 Department of Computer Science College of Engineering Boise State University January 14, 2017 1/30 Motivation Most programming tasks can be implemented using abstractions (e.g. representing data
COMP 122/L Lecture 2. Kyle Dewey
COMP 122/L Lecture 2 Kyle Dewey Outline Operations on binary values AND, OR, XOR, NOT Bit shifting (left, two forms of right) Addition Subtraction Twos complement Bitwise Operations Bitwise AND Similar
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
E-COMMERCE SOLUTIONS BASED ON THE EDI STANDARD. Inna I. Stoianova, Roumen V. Nikolov, Vanyo G. Peychev
МАТЕМАТИКА И МАТЕМАТИЧЕСКО ОБРАЗОВАНИЕ, 2002 MATHEMATICS AND EDUCATION IN MATHEMATICS, 2002 Proceedings of Thirty First Spring Conference of the Union of Bulgarian Mathematicians Borovets, April 3 6, 2002
Introduction to Computer Science Midterm 3 Fall, Points
Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do
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: +, -, ++, --,!, ~
Structures, Operators
Structures Typedef Operators Type conversion Structures, Operators Basics of Programming 1 G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A. Vitéz 10 October, 2018 c based on slides by Zsóka, Fiala, Vitéz
Operators. Lecture 3 COP 3014 Spring January 16, 2018
Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator
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;
Unit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=
Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic
Signed umbers. Sign/Magnitude otation
Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,
Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course
Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course Irena Pevac Department of Computer Science Central Connecticut State University, New Britain, CT, USA Abstract: We propose
Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example
Appendix F Number Systems Binary Numbers Decimal notation represents numbers as powers of 10, for example 1729 1 103 7 102 2 101 9 100 decimal = + + + There is no particular reason for the choice of 10,
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
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.
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
CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators
CSE 351: The Hardware/Software Interface Section 2 Integer representations, two s complement, and bitwise operators Integer representations In addition to decimal notation, it s important to be able to
Introduction to Algorithms Third Edition
Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Introduction to Algorithms Third Edition The MIT Press Cambridge, Massachusetts London, England Preface xiü I Foundations Introduction
CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion
CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion Review from Lectures 5 & 6 Arrays and pointers, Pointer arithmetic and dereferencing, Types of memory ( automatic, static,
Introduction to C Language
Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,
OBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object
Section we will not cover section 2.11 feel free to read it on your own
Operators Class 5 Section 2.11 we will not cover section 2.11 feel free to read it on your own Data Types Data Type A data type is a set of values and a set of operations defined on those values. in class
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
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
Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators
Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships
A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.
1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object
from Appendix B: Some C Essentials
from Appendix B: Some C Essentials tw rev. 22.9.16 If you use or reference these slides or the associated textbook, please cite the original authors work as follows: Toulson, R. & Wilmshurst, T. (2016).
Consider the actions taken on positive integers when considering decimal values shown in Table 1 where the division discards the remainder.
9.3 Mapping Down to 0,..., M 1 In our previous step, we discussed methods for taking various objects and deterministically creating a 32- bit hash value based on the properties of the object. Hash tables,
Computers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
Number Systems CHAPTER Positional Number Systems
CHAPTER 2 Number Systems Inside computers, information is encoded as patterns of bits because it is easy to construct electronic circuits that exhibit the two alternative states, 0 and 1. The meaning of
Bits and Bytes. Bit Operators in C/C++
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
Contents of Lecture 3
Contents of Lecture 3 Repetition of matrices double a[3][4]; double* b; double** c; Terminology Linkage Types Conversions Jonas Skeppstedt (js@cs.lth.se) Lecture 3 2014 1 / 33 A global matrix: double a[3][4]
Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
MATLAB. Devon Cormack and James Staley
MATLAB Devon Cormack and James Staley MATrix LABoratory Originally developed in 1970s as a FORTRAN wrapper, later rewritten in C Designed for the purpose of high-level numerical computation, visualization,
JOINT-STOCK COMPANY GIDROPRIVOD. RADIAL PISTON PUMPS OF VARIABLE DISPLACEMENT type 50 НРР
JOINT-STOCK COMPANY GIDROPRIVOD RADIAL PISTON PUMPS OF VARIABLE DISPLACEMENT type 50 НРР Item purpose Radial piston pumps of variable displacement of the type 50НРР with adjustable delivery and constant
C: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
C++11: C++ AS CONTEMPORARY PROGRAMMING LANGUAGE
Годишник на секция Информатика Съюз на учените в България Том 6, 2013, 111 119 Annual of Informatics Section Union of Scientists in Bulgaria Volume 6, 2013, 111 119 C++11: C++ AS CONTEMPORARY PROGRAMMING
4WCE * 5 * : GEO. Air Products and Chemicals, Inc., 2009
ХН Ч АН А 4WCE-600700* 5 9 2015. 1 93 : * : 600.700 600.730 1. 2 2. 2 3. 2 4. 3 5. 5 6. 7 7.,,, 8 8. 9 9., 10 10. 12 11., 13 12. 14 13. 16 14. 16 15. 17 16. 17 17., 18 18. 21 19., 24 20., 25 21., 26 22.