The Littleendian Method Yesterday we learned how to convert bases with the bigendian metod. We begain at the "big end" and worked our way down.
- input: an integer n
- List powers of the base until the number is exceeded.
- These are denominations of "bills." Use the money procedure to count out n units using as few bills as possible by using as many as you can with the highest denomonation
- Numbers of bills can be combined to get base conversion.
Now consder this.
69 *1 Since 69 is odd, we know its binary expansion ends in a 1. The * is a wildcard representing any glob of 0s and 1s. 34 *01 69//2 = 34. this chops the last digit off. It reveals the second to last digit is a 0. 17 *101 Repeat this procedure until you whittle down to 0. 8 *0101 4 *00101 2 *000101 1 *1000101 0 1000101 We have all of the digits!
Now let's try this on base 5.
69 *4 69%5 = 4 13 *34 69//13 = 5 and 13%5 = 3. 2 *234 13//5 = 3 and 2%5 = 2 0 234 we have the digits.
In any base b,
- mod by base to get last digit
- integer divide by base to chop off last digit once it's known.
Let's convert 121 into octal and binary.
Base 8: 0o171 (0o is a prefix meaning "this is an octal number") Base 2: 0b1111001
Packing-Unpacking Procedure packing: hree bits pack into one octal digit because 23 = 8. 1 111 001 1 7 1 → 0o171 Unpacking 1 7 1 001 111 001 0b1111001 Hexadecimal {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} 0xa4b a 4 b 1010 0100 1011 0b101001001011 Packing is the same as octal.
A Base Changing Practicepalooza
Hex Numbers and Colors Download colorDemo.zip from the navigation bar on the left. Decompress it and open the files with VSCode. Look in the CSS file, and you will see this.
/*Author: Morrison*/
h1, h2, .display
{
text-align:center;
}
body
{
background-color:#FFFFFF;
}
Change the 6-digit hex number inside of the body
style rule. Then, in your browser, choose File → Open... and
open the HTML file. Let's pool our knowledge.
red | FF0000 | |
---|---|---|
green | ||
blue | 0000FF | |
yellow | FFFF00 | |
black | 000000 | |
white | FFFFFF | |
magenta | FF00FF | |
cyan | 00FFFFF |
Playing with Pythons
What is an object? An object is an item stored in memory. Objects have three attributes.
- state: This is what an object KNOWS.
- identity: This is what an object IS.
- behavior: This is what an object DOES.
All data in Python are represented as objects. Python, like every other language, has a type ecosystem. In this portion of the course, we will being by learning about Python's scalar types. Later, we will address sequences, sets, and dictionaries.
Your class's Python session is in the file 0203B.txt
which you can download from the navigation area.