Binary Representation

Slides:



Advertisements
Similar presentations
Review of HTML Ch. 1.
Advertisements

1 Chapter 2 The Digital World. 2 Digital Data Representation.
Review Ch.1,Ch.4,Ch.7. Review of tags covered various header tags Img tag Style, attributes and values alt.
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, Java Version, Third Edition.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Level ISA3: Information Representation
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Chapter 2 Data Types, Declarations, and Displays
Data Representation in Computers
SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.
The Binary Number System
2.1 2 Number Systems Foundations of Computer Science  Cengage Learning.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Real Numbers and the Decimal Number System
(2.1) Fundamentals  Terms for magnitudes – logarithms and logarithmic graphs  Digital representations – Binary numbers – Text – Analog information 
Programmable Logic Controllers
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
MATH 224 – Discrete Mathematics
Numeral Systems Subjects: Numeral System Positional systems Decimal
IT-101 Section 001 Lecture #3 Introduction to Information Technology.
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
Logic Design Dr. Yosry A. Azzam. Binary systems Chapter 1.
Binary Numbers. Why Binary? Maximal distinction among values  minimal corruption from noise Imagine taking the same physical attribute of a circuit,
Chapter 7—Objects and Memory The Art and Science of An Introduction to Computer Science ERIC S. ROBERTS Java Objects and Memory C H A P T E R 7 Yea, from.
1 3 Computing System Fundamentals 3.5 Data Representation.
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
THE BINARY SYSTEM.
Data Representation, Number Systems and Base Conversions
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
Data Representation. What is data? Data is information that has been translated into a form that is more convenient to process As information take different.
Systems Architecture, Fourth Edition 1 Data Representation Chapter 3.
1 Problem Solving using Computers “Data....Representation, and Storage.
Data Representation Eric Roberts CS 106A February 10, 2016.
Chapter 3 Boolean Algebra and Digital Logic T103: Computer architecture, logic and information processing.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Computer Representation of Information
Binary Representation in Text
Binary Representation in Text
Understanding binary Understanding Computers.
Invitation to Computer Science, C++ Version, Fourth Edition
Programming and Data Structure
NUMBER SYSTEMS.
Number Representation
Chapter 3 Data Storage.
Data Representation in Computer Systems
EPSII 59:006 Spring 2004.
Introduction The term digital is derived from the way computers perform operation, by counting digits. Application of digital technology: television, communication.
Chapter 3 Data Representation
Fundamentals & Ethics of Information Systems IS 201
Binary Representation
Invitation to Computer Science, Java Version, Third Edition
Objects and Memory Eric Roberts CS 106A February 5, 2010.
Bases and Representations, Memory, Pointers, Arrays, For-Loops
Ch2: Data Representation
Numbering System TODAY AND TOMORROW 11th Edition
Data Representation Conversion 05/12/2018.
Plan Attendance Files Posted on Campus Cruiser Homework Reminder
Storing Negative Integers
How Computers Store Data
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Chapter 7—Objects and Memory
Comp Org & Assembly Lang
Beyond Base 10: Non-decimal Based Number Systems
WJEC GCSE Computer Science
Chapter 3 - Binary Numbering System
CHAPTER 69 NUMBER SYSTEMS AND CODES
Digital Representation of Data
Presentation transcript:

Binary Representation Jerry Cain CS 106AJ October 29, 2018 slides courtesy of Eric Roberts

Once upon a time . . .

Claude Shannon Claude Shannon was one of the pioneers who shaped computer science in its early years. In his master’s thesis, Shannon showed how it was possible to use Boolean logic and switching circuits to perform arithmetic calculations. That work led directly to the use of binary arithmetic inside computers—an idea that initially generated considerable resistance among more established scientists. Claude Shannon (1916-2001) Shannon is best known as the inventor of information theory, which provides the mathematical foundation for understanding data communication. To many, however, Shannon’s great contribution was that he never lost his sense of fun throughout his long career.

Binary Representation

The Power of Bits The fundamental unit of memory inside a computer is called a bit—a term introduced in a paper by Claude Shannon as a contraction of the words binary and digit. An individual bit exists in one of two states, usually denoted as 0 and 1. More sophisticated data can be represented by combining larger numbers of bits: Two bits can represent four (2 × 2) values. Three bits can represent eight (2 × 2 × 2) values. Four bits can represent 16 (24) values, and so on. This laptop has 16GB of main memory and can therefore exist in 2137,438,953,472 states, because 16GB is really 237 = 137,438,953,472 independent bits.

Leibniz and Binary Notation Binary notation is an old idea. It was described back in 1703 by the German mathematician Gottfried Wilhelm von Leibniz. Writing in the proceedings of the French Royal Academy of Science, Leibniz describes his use of binary notation in a simple, easy-to-follow style. Leibniz’s paper further suggests that the Chinese were clearly familiar with binary arithmetic 2000 years earlier, as evidenced by the patterns of lines found in the I Ching.

Using Bits to Represent Integers Binary notation is similar to decimal notation but uses a different base. Decimal numbers use 10 as their base, which means that each digit counts for ten times as much as the digit to its right. Binary notation uses base 2, which means that each position counts for twice as much, as follows: 1 0 x 128 = 0 x 64 = 0 x 16 = 1 x 8 = 1 x 32 = 0 x 1 = The next digit gives the number of 4s. The next digit gives the number of 2s. The rightmost digit is the units place. 1 x 2 = 0 x 4 = 42

Numbers and Bases The calculation at the end of the preceding slide makes it clear that the binary representation 00101010 is equivalent to the number 42. When it is important to distinguish the base, the text uses a small subscript, like this: 001010102 = 4210 Although it is useful to be able to convert a number from one base to another, it is important to remember that the number remains the same. What changes is how you write it down. The number 42 is what you get if you count how many stars are in the pattern at the right. The number is the same whether you write it in English as forty-two, in decimal as 42, or in binary as 00101010. Numbers do not have bases; representations do.

Octal and Hexadecimal Notation Because binary notation tends to get rather long, computer scientists often prefer octal (base 8) or hexadecimal (base 16) notation instead. Octal notation uses eight digits: 0 to 7. Hexadecimal notation uses sixteen digits: 0 to 9, followed by the letters A through F to indicate the values 10 to 15. The following diagrams show how the number forty-two appears in both octal and hexadecimal notation: 2 x 2 1 5 x 40 8 5 42 10 x 10 02 x 32 16 A octal hexadecimal = The advantage of using either octal or hexadecimal notation is that doing so makes it easy to translate the number back to individual bits because you can convert each digit separately.

Exercises: Number Bases What is the decimal value for each of the following numbers? 100012 1778 AD16 1 x 1 0 x 2 4 8 16 17 17 7 x 7 1 56 8 127 1 x 64 127 173 13 x 13 1 10 x 160 16 A D 173 As part of a code to identify the file type, every Java class file begins with the following sixteen bits: 1 How would you express that number in hexadecimal notation? 1 A F E CAFE16

Exercise: Perfect Numbers in Binary Greek mathematicians took a special interest in numbers that are equal to the sum of their proper divisors, which are simply those divisors less than the number itself. They called such numbers perfect numbers. For example, 6 is a perfect number because it is the sum of 1, 2, and 3, which are the integers less than 6 that divide evenly into 6. The next three perfect numbers—all of which were known to the Greeks—are 28, 496, and 8128. 6 = Convert each of these numbers into its binary representation: 28 496 8128 1102 111002 1111100002 11111110000002

Bits and Representation Sequences of bits have no intrinsic meaning except for the representation that we assign to them, both by convention and by building particular operations into the hardware. As an example, a 32-bit word represents an integer only because we have designed hardware that can manipulate those words arithmetically, applying operations such as addition, subtraction, and comparison. By choosing an appropriate representation, you can use bits to represent any value you can imagine: Characters are represented using numeric character codes. Floating-point representation supports real numbers. Two-dimensional arrays of bits represent images. Sequences of images represent video. And so on . . .

Representing Characters Computers use numeric encodings to represent character data inside the memory of the machine, in which each character is assigned an integral value. Character codes, however, are not very useful unless they are standardized. When different computer manufacturers use different coding sequence (as was indeed the case in the early years), it is harder to share such data across machines. The first widely adopted character encoding was ASCII (American Standard Code for Information Interchange). With only 256 possible characters, the ASCII system proved inadequate to represent the many alphabets in use throughout the world. It has therefore been superseded by Unicode, which allows for a much larger number of characters.

The ASCII Subset of Unicode The following table shows the first 128 characters in the Unicode character set, which are the same as in the older ASCII scheme: The letter A, for example, has the Unicode value 1018, which is the sum of the row and column labels. The Unicode value for any character in the table is the sum of the octal numbers at the beginning of that row and column. 1 2 3 4 5 6 7 00x \000 \001 \002 \003 \004 \005 \006 \007 \b \t \n \011 \f \r \016 \017 \020 \021 \022 \023 \024 \025 \026 \027 \030 \031 \032 \033 \034 \035 \036 \037 space ! " # $ % & ' ( ) * + , - . / 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ \177 \000 \001 \002 \003 \004 \005 \006 \007 \b \t \n \011 \f \r \016 \017 \020 \021 \022 \023 \024 \025 \026 \027 \030 \031 \032 \033 \034 \035 \036 \037 space ! " # $ % & ' ( ) * + , - . / 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ \177 01x 02x 03x 04x 05x 06x 07x 10x 11x 12x 13x 14x 15x 16x 17x

Hardware Support for Characters =97 1 1 1

Strings as an Abstract Idea Characters are most often used in programming when they are combined to form collections of consecutive characters called strings. As you will discover when you have a chance to look more closely at the internal structure of memory, strings are stored internally as a sequence of characters in sequential memory addresses. The internal representation, however, is really just an implementation detail. For most applications, it is best to think of a string as an abstract conceptual unit rather than as the characters it contains. JavaScript emphasizes the abstract view by defining a built-in string type that defines high-level operations on string values.

The End