DOC PREVIEW
TAMU CSCE 110 - Binary
Type Lecture Note
Pages 3

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSCE 110 1nd EditionLecture 21Outline of Last Lecture:I. Nested FunctionsA. IntroductionB. ScopesII. Inverting a dictionaryOutline of Current Lecture:I. BinaryA. Going from base 10 to base 2B. Going from base 2 to base 10II. Program that converts to and from binaryCurrent Lecture:I. BinaryLet's start by saying that the numbers we use in everyday life are in base 10. What we will learn in these set of notes is binary, the number language that computers speak. From first glance, binary just looks like a series of 1's and 0's, but they really represent the numbers you and I know so well. By the end of these notes you will be able to convert numbers from base 10 to base 2 (binary), and vice versa. A. Converting from base 2 to base 10The following are equivalent:a) 22b) 10110The second is in base 2, so let's break it down and see why it is equal to 22 (in base 10).1 0 1 1 02423222120As you can see, each 1 and 0 corresponds to the number 2 raised to some power. With binary, we read from right to left, which can be confusing. On the far right, we start with 20, and as we move to the left, we have 21, then 22, and so on, continuing until the leftmost 1 or 0. Let's look at 10110 again, this time with each 2n written below in base 10.1 0 1 1 0These notes represent a detailed interpretation of the professor’s lecture. GradeBuddy is best used as a supplement to your own notes, not as a substitute.242322212016 8 4 2 1What do these numbers mean? Well, if we multiply each 2n number with its corresponding 1 or 0 and add all these numbers together, we will have successfully converted a number from binary to base 10. Let's look:(1)(24) + (0)(23) + (1)(22) + (1)(21) + (0)(20)= (1)(16) + 0 + (1)(4) + (1)(2) + 0= 22It's not that difficult to grasp, it just takes some practice before one can become familiar with binary. After all, you've been doing the same with numbers in base 10 all this time, probably without even realizing it:9 1 7102101100100 10 1(9)(102) + (1)(101) + (7)(100)= (9)(100) + (1)(10) + (7)(1)= 917B. Converting from base 10 to base 2This process is a tad more complicated, but not too difficult. Let's look at the number 22 again, and convert it to base 2. What's the highest 2n value that is within 22? That would be 24, which is 16. Let's start our table,this time going from left to right:1 ? ? ? ?2423222120We have a 1 in the 24 place because it is within 22. Now, to figure out if a 1 or 0 goes in the 23 location, we must first subtract 24 from what we started with. So, 22 - 16 = 6. We will move on with the number 6.Does 23 fit within 6? 23 is 8, so no, 8 is not within 6, and we will put a 0 in this location. 1 0 ? ? ?2423222120 We still have three more locations to fill in.Because we didn't have a 1 in the 23 location, there is nothing to subtract from 6, which is where we left off. Moving on:Does 22 fit within 6? 22 is 4, so yes. We will put a 1 in the 22 location, and we subtract from 6. 6 - 4 = 2, so next we will look at 2.1 0 1 ? ?2423222120 Does 21 fit within 2? 21 is 2, so yes, and we will put a 1 in the 21 location. 1 0 1 1 ?2423222120Now, we can realize that 2 - 2 = 0, so we know that no number is within 0, so we can automatically put a 0 in any remaining 2n locations (in this case, the only place we had left was 20). 1 0 1 1 02423222120As we can see, we have 10110 in base 2, which is what we wanted. Note that the only time we will have a 1 in the 20 location is when we are representing a numberthat is odd in base 10, otherwise we have no need for that extra


View Full Document

TAMU CSCE 110 - Binary

Type: Lecture Note
Pages: 3
Documents in this Course
06-IO

06-IO

29 pages

21-OOP

21-OOP

8 pages

key

key

6 pages

21-OOP

21-OOP

8 pages

Load more
Download Binary
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Binary and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Binary 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?