Lecture-5 Miscellaneous. Random Numbers Can use ‘rand()’ function declared in the stdlib.h header file The seed for random number generation can be set.

Slides:



Advertisements
Similar presentations
OBJECTIVES You should be able to:  Convert binary fractions to a decimal  Convert decimal fractions to binary.
Advertisements

Exercise 4 1. Write a program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. Let the program toss the.
Binary Addition Rules Adding Binary Numbers = = 1
Assembly Language and Computer Architecture Using C++ and Java
Kavita Hatwal Fall The decimal system, also called the base 10 number system is based on ten numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. All the numbers.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Multiplying Decimals Cornell Notes.
FIGURES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
They are the same as registers since they store binary numbers. Called shifting registers since they shift (left or right) the binary number stored in.
Objective: Learn to multiply and divide integers.
Binary Number Systems.
Data Representation in Computers. Data Representation in Computers/Session 3 / 2 of 33 Number systems  The additive approach – Number earlier consisted.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
The Binary Number System
1 Survey of Computer Science CSCI 110, Spring 2011 Lecture 16 Digital Circuits, binary Numbers.
Simple Data Type Representation and conversion of numbers
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
Advanced Instructions Most PLCs now support more advanced functions such as Floating point math, Boolean operations, Shifting, Sequencing, Program control.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved.1 Chapter 3 Selections.
Logic Design Dr. Yosry A. Azzam. Binary systems Chapter 1.
– Digital Circuit 1 Choopan Rattanapoka
Operations with Scientific Notation. Addition and Subtraction Format Addition (N * 10 x ) + (M * 10 x ) = (N + M) * 10 x Subtraction (N * 10 y ) - (M.
Lecture-2 Operators and Conditionals. Variables(again???) Type: Representation of “bits” in memory Variables: Name for a memory object. Starts with letters,
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
Number systems, Operations, and Codes
Exponents.
CSC 221 Computer Organization and Assembly Language
Introduction to Numerical Analysis I MATH/CMPSC 455 Binary Numbers.
Multiplying and Dividing Integers When you MULTIPLY: Two positives equal a positive Two negatives equal a positive One positive & one negative equal.
Operations on Bits Arithmetic Operations Logic Operations
Introduction to Pascal The Basics of Program writing.
 2008 Pearson Education, Inc. All rights reserved Case Study: Random Number Generation C++ Standard Library function rand – Introduces the element.
C++ Programming Lecture 10 Functions – Part II
Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * *
Visualizing Decimal and Binary
Dividing Decimals TeacherTwins©2014. Warm Up
Dividing a Decimal by a Decimal. Dividing Whole Numbers 12 ÷ 2 = 120 ÷ 20 = 1200 ÷ 200 = ÷ 2000 = Multiply both 12 and 2 by 10 Multiply.
UNIT 6 VOCABULARY By: Marissa. A value of something that does not change. Example: A is always A. Constant Term.
Integer Exponents. Look for a pattern in the table to extend what you know about exponents to include negative exponents. ÷ –1 10 –
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Positive Integers Dale Roberts,
EEE342 Digital Electronics Ian McCrumRoom 5B18, Lecture 2: Codes & Arithmetic.
Scientific Notation What is scientific Notation? Scientific notation is a way of expressing really big numbers or really small numbers. It.
Lecture 6: Floating Point Number Representation Information Representation: Floating Point Number Representation Lecture # 7.
Binary & Normalization What is Normalization? We discussed this the other day (special review session slides, near the end) Can someone tell us.
Learning Objectives 3.3.1f - Describe the nature and uses of floating point form 3.3.1h - Convert a real number to floating point form Learn how to normalise.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Number systems Visualizing Decimal and Binary. We count in base 10 because people started by counting on their fingers Base 10 is a number system that.
COMPUTER ARITHMETIC Binary Coded Decimal Presented By Chung Wai Chow.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
♣Multiplying Decimals♣
Chapter 4 Operations on Bits.
COMPUTING FUNDAMENTALS
Scientific Notation with Positive Powers
Chapter 2: Number Systems
How is 0.41  10 related to 0.41  100?.
The basics of any electronic device means either electricity is flowing or it is not i.e. a switch is either on or off Computers are electronic devices.
Lecture No.5.
Information Representation
Review Lab assignments Homework #3
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Multiplying and Dividing Decimals
Lecture 37 – Practice Exercises 9
Lecture 37 – Practice Exercises 9
Presentation transcript:

Lecture-5 Miscellaneous

Random Numbers Can use ‘rand()’ function declared in the stdlib.h header file The seed for random number generation can be set using srand() A good seed can be the ‘time()’ function defined in time.h header file Follow this link to test_ran.ctest_ran.c

In-class Exercise 6-1 Write a program to guess a number Generate a random number from 1 to 10 using: 1 + rand() % 10 Prompt the user to enter a number(from 1 to 10), find out of the number is equal to, less than, or greater than the random number Keep prompting user till he enters a negative value.

Decimal Number System Numbers with the base value of 10 Digits used: {0, 1, 2,…, 9} 1362: 1* * * *10 0 In general, any number with ‘n’ number of digits can be represented as: d n.10 n +d n-1.10 n-1 +….d

Binary Numbers Numbers represented with base value of 2 Only two digits used: {0, 1} Binary digits are frequently called “bits”, and can be visualized as an “on-off” operation for a electronic switch 1011: : = 11(decimal)

Bit Operations C has bit operators with operate on integers as bit patterns Each bit from each integer is acted upon separately The answer is presented in integer format Follow this link to bit_opr.cbit_opr.c

Operator table XYAND(X&Y)OR(X|Y)XOR(X^Y) Complement Operator(!): Inverts value Thus: !1 = 0, and !0 = 1

Shift operators Shift operators can shift bits of a variable either left or right Shifting bits to left is equivalent to multiplying by 2 Shifting bits to right is equivalent to dividing by 2 Follow this link to bit_shift.cbit_shift.c

In-class Exercise 6-2 Write a program to print out the multiplication table of 2 Use bit-shift operators for each number to multiply the number by two, and then display it. Use the range of number from 1 to 10