AP Computer Science Java Programming - Binary and Hexadecimal
Binary and Hexadecimal Numbers
- People are used to base 10 numbers, this is totally different. Read from right to left to do the math.
Ex. 256
- Binary is similar, but base 2, using only 0 and 1.
Ex. 100110
- Hexadecimal is similar, but base 16, using 0-9 and A-F (10-15). Notice there are 16 numbers and letters total.
Ex. 14D2
AP Sample Problems
Example 1
Suppose that base-2 (binary) numbers and base-16 (hex)
numbers can be denoted with subscript, as shown below:
2Ahex = 101010binary
Which is equal to 3Dhex?
(a) 111101
(b) 101111
(c) 10011
- Check all three with the math that I showed you from before and see which one is equivalent to 3D hex, or 61 in our regular numbering system.
Answer: (a) 111101 = 1 + 4 + 8 + 16 + 32
Example 2
An example of a hex color is (238, 9, 63) --> ##EE093F
Which of the following would be (14, 20, 255)?
- Notice that the second number 9 is still 9 in the color code. The other two numbers are in hex, so convert 14 and 255 to hex, they are E and FF.
Answer: ##0E20FF
Example 3
Consider the code segment:
int x = 10, y=0;
while (x > 5) {
y = 3;
while (y < x) {
y *= 2;
if (y % x == 1) {
y += x;
}
}
x -= 3;
}
System.out.println(x + “ “ + y);
- This code will run the outside while loop three times, changing the x and y values several times. You must read it line by line, as the computer would, until it is over.
Answer: 4 12
Classwork/Homework:
Write a program that takes a binary number from the user,
entered only zeros and ones, that converts it to base 10 (our
regular number system). Only 4 digit numbers, like 1010 or 1110
or 0001. (Using mod operator is probably the best way).
Now, here are some outputs of my program:
All SteemitEducation Posts
Physics
Kinematics Video, Circular Motion Video, Forces in 1 & 2 Dimensions Videos, Kinematics Full Lesson, Circular Motion and Gravitation Full Lesson
Computer Science
SAT
Asymptotes, Composite Functions, Contest 1 - Area, Contest 1 – Winners and Solution, PEMDAS, Systems of Equations, Functions, Exponents, Contest 2 - More Functions, Contest 2 – Winners and Solution, Percents, The Interest Equation, All About Division, Contest 3 - Factoring, Contest 3 – Winners and Solution, Fractional and Negative Exponents, Basic Trig, Contest 4 - Math Vocab
General Math
Basics of Algebra, Trigonometry Video, Proof of Quadratic Formula, Factoring Video, Unions and Intersections, Surface Area of a Cylinder, Substitution Video, Combinatorics Basics
Graphing from Algebra to Calculus
Algebra 1, Algebra 2, Pre-Calculus, Calculus
Piloting Airplanes
Introduction, Preflight, Requirements, Instruments, Take-Offs and Landings, Why a Plane Can Fly, Reading the Runway, Maneuvers
Other
Engineering (Isometric) Drawing, Pressure & SCUBA Diving
Nice post like always :)
Keep up the good work.
This post has received a 100% upvote worth $0.06 from @minnowspower thanks to: @theguruasia
MinnowsPower is not a bot, I am a Crowdfunding Hybrid
One small UpVote of Yours build MinnowsPower and MinnowsPower will Not Forget Your Support...!!!
(Limited Service Offer) Send 0.01 SBD and get $0.025 - $0.03 worth upvote from @MinnowsPower