12. 22 | Laboratory 3
DELIVERABLES
Turn in your handwritten sheets showing your answers to the
exercises.
DEEPER INVESTIGATION
Computers love binary because of the bistable devices out of
which we build them. These
devices have only two stable states, ideal for representing 0 and
1 but nothing else. But
the fact that we like to see numbers in decimal form and
computers work in binary leads
to some problems, similar to the impossibility of representing
1/3 exactly as a decimal
fraction.
In the Real Numbers Representations app, type in “0.333” and
press Return. Write
down what you see in the scientific notation area. Then type in
“0.3333” and repeat. Are
you surprised? Why do you suppose the app prints out this
weird value?
Now type in “0.1” (one-tenth) and press Return, looking at the
binary representation
at the bottom of the screen. It is a bit deceptive to look at what
the app puts out. Try to
come up with some combination of the negative powers of 2
that exactly equals 0.1.
Can you do it? What does that mean about a computer
representing 0.1? (You mean a
computer can’t even represent 10 cents?!?!?!)
18. still pictures, moving pictures, smells, . . . Wait! Smells? No,
not yet (perhaps never!).
Now that we know how numbers of all kinds are represented
using 1s and 0s, the
next step is to learn how characters are represented. A character
“mapping” assigns
a number to each character, and then this assigned number is
encoded in binary.
For example, a very simple mapping scheme might assign 1 to
A, 2 to B, and so on.
A computer would then store B as 10, the binary representation
of 2. It is as simple as
that—except for making everyone agree on which mapping to
use!
Pitched battles have been fought over character mappings. Well,
that is a bit of an
exaggeration, but it did take a long time for the computer
industry to stop using many
different mappings. IBM mainframes used EBCDIC, while
Control Data Corporation
(CDC) supercomputers used their own system. Digital
Equipment Corporation (DEC) and
other smaller companies used ASCII. Perhaps the big
breakthrough came when the IBM
PC was announced in 1981. Though it was an IBM, it used
ASCII, and ASCII has grown
ever since, to the point that it is practically the only character
mapping used nowadays.
Except for Unicode, that is. With the advent of Java and web
browsers and the
growing international community of computer users, the
Unicode character mapping
has enabled us to encode virtually every written symbol as a 16-
21. NOT FOR SALE OR DISTRIBUTION
Colorful Characters | 25
After typing “192” in the numeric code text area, press Return
and you will see À, which
is the letter A with a grave accent. You could also have typed
“0xC0,” which is the
hexadecimal number for 192. (The 0x in front is a prefix
designating that the following
number is base 16, or hexadecimal. x is often an abbreviation
for hexadecimal and is seen
in programming languages like C.)
Try the example buttons. Example 3 cycles through all
characters from 33 up to 255.
If your computer can’t represent a certain character, Java
substitutes a little square.
❯ Part 2
The Text Translator into ASCII app makes it easy to type in
some text and have the
computer translate all of it to binary using the ASCII character
mapping.
Start the app. Notice the character mapping in the tall text area
on the left. It starts
at 32, which just happens to be the blank character, and ends at
127. The codes that are
mapped into the numbers 0 through 31 and 127 on up are
unprintable. They have names
and some are used in various functions, but in general they do
not produce any graphical
image on the screen.
24. 26 | Laboratory 4
of them for PC graphics. Then Unicode came along and
redefined it all again. But the
128 codes with numeric values from 0 to 127 have remained
stable.
You can look up tables for all 128 ASCII characters online; just
search for “ASCII
table” in your favorite search engine and inspect a table you
find. Notice that one of the
characters, number 8, is called BEL. Can you guess what it
does? (It sounds a beep on the
computer.) Many of the others were used in early
telecommunications equipment. For
example, STX is “Start of text” and ACK is “Acknowledge.”
❯ Part 3
The Color Maker app shows you two ways that colors can be
encoded using 1s and 0s.
The first method is called “RGB” because it represents colors as
combinations of three
intensity values of the colors red, green, and blue. The second
method is called “HSB”
because it represents colors as combinations of three values on
the scales of hue,
saturation, and brightness.
To begin, start the Color Maker app, and select Red from the
color name choice pull-
down menu in the bottom-left corner. The app sets the
scrollbars and text areas to the
values according to the RGB encoding and the HSB encoding.
30. Turn in your handwritten sheets showing your answers to the
exercises. Also turn in one
screenshot for the Text Translator into ASCII app and another
screenshot for the Color
Maker app.
DEEPER INVESTIGATION
The CDC character set started with A = 1, B = 2, C = 3, and so
forth. If you were creating
a character mapping, this is probably what you would do.
However, the CDC character
set didn’t have lowercase letters like a, b, or c. (The original
character set used six bits, so
there weren’t enough possible number combinations.)
ASCII and EBCDIC do not use A = 1, or even a = 1. However,
there are regularities
in the character coding scheme. You discovered one such
regularity in the previous
exercises. Are there any others in ASCII that you can find?
Try to find a listing of EBCDIC’s codes, most likely online.
You will find some
surprises. For example, A = 193, B = 194, C = 195, . . . and I =
201. But J = 209. What?!?!?
There are no similar breaks in ASCII. There was a reason for
the breaks in EBCDIC, but
you may have to dig to find out what it is. (Hint: If you get
stuck, punch the keys of your
computer, but not too hard!)
Switching to a different train of thought, think about how
arbitrary encodings tend
to be. Suppose we wanted to encode the four primary directions
of the compass. Would
we choose north = 1, south = 2, east = 3, and west = 4? Are
38. Negatives.classpublicsynchronizedclass Negatives extends
java.awt.Frame implements java.awt.event.ActionListener,
java.awt.event.ComponentListener, java.awt.event.TextListener
{
java.awt.TextField binary1TF;
java.awt.TextField binary2TF;
java.awt.TextField decimalTF;
java.awt.TextField numDigitsTF;
java.awt.Button convertB;
java.awt.Label Label1;
java.awt.Label Label2;
java.awt.Label Label3;
java.awt.Label Label4;
java.awt.Image buffer;
java.awt.Graphics gg;
java.awt.Font labelFont;
publicstatic void main(String[]);
public void Negatives();
public void actionPerformed(java.awt.event.ActionEvent);
public void textValueChanged(java.awt.event.TextEvent);
public void
componentResized(java.awt.event.ComponentEvent);
public void
componentHidden(java.awt.event.ComponentEvent);
public void
componentMoved(java.awt.event.ComponentEvent);
public void
componentShown(java.awt.event.ComponentEvent);
public void paint(java.awt.Graphics);
public void update(java.awt.Graphics);
private void convertBinary();
private String convert(long, int);
private String make2sComplement(String, boolean);
}
39. Popup$1.classsynchronizedclass Popup$1 extends
java.awt.event.WindowAdapter {
void Popup$1(Popup);
public void windowClosing(java.awt.event.WindowEvent);
}
Popup.classsynchronizedclass Popup extends java.awt.Frame {
java.awt.TextArea ta;
public void Popup(String);
}
U.classpublicsynchronizedclass U {
public void U();
publicstatic int atoi(String);
publicstatic long atol(String);
publicstatic String[] copy(String[]);
publicstatic String[] tokenize(String);
publicstatic String[] tokenize(String, String);
publicstatic String detokenize(String[]);
publicstatic boolean equals(String[], String[]);
publicstatic void sleep(long);
publicstatic long power(int, int);
publicstatic boolean isint(String);
}
Applets_Lab3/Text Encoding in ASCII.jar
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0_38 (Sun Microsystems Inc.)
Main-Class: TextCodes
40. TextCodes$1.classsynchronizedclass TextCodes$1 extends
java.awt.event.WindowAdapter {
void TextCodes$1(TextCodes);
public void windowClosing(java.awt.event.WindowEvent);
}
TextCodes.classpublicsynchronizedclass TextCodes extends
java.awt.Frame implements java.awt.event.ActionListener {
java.awt.TextArea input;
java.awt.TextArea output1;
java.awt.TextArea output2;
java.awt.Button translateButton;
java.awt.Color bg;
java.awt.TextArea bigTA;
staticfinal int highestNumber = 256;
java.awt.Image buffer;
java.awt.Graphics gg;
publicstatic void main(String[]);
public void TextCodes();
public void actionPerformed(java.awt.event.ActionEvent);
publicstatic int atoi(String);
private void translate();
private String convert(int, int);
}
CS1150 Introduction to Computer Science
Lab #3 – Representing Numbers, 40 points
Objective:
To understand how negative and real numbers encoded inside
41. computers.
Instructions:
Make sure to do the Activities as outlined in the LabCH03.pdf
and LabCH04.pdf files. The activity is actually a tutorial that
will help you to solve the problems in the exercises. It is
expected that you will complete the Activities before you begin
the exercises.
When you are finished, save and rename the completed
document as “firstname_lastname_lab3.docx”. Then, submit
the saved document to Pilot.
Activity:
1. LabCH03.pdf
· Activity
· Part 1
2. LabCH04.pdf
· Activity
· Part 1
· Part 2
· Part 3
Exercise 1: Representing Negative Numbers
1) Start the “Negative binary numbers” applet.
a. Type in -1 and press “Enter” key. Study the result. Find
the “sign bit”. How does the applet indicate it? Come up with a
theory of how the sign bit is indicated/ what the rule is for
determining which bit is the sign bit. Try and test your theory to
be sure. See if you can prove and/or disprove it. Write down
42. your theory of how the sign bit is indicated:
b. Change the number of bits to 32 in the text field “Number
of digits in binary” and convert -1 again. Write down how the
two forms of binary -1 are different in 32 bits compared to 8
bits. (Feel free to convert -1 into 8 bits again to see the
different forms.)
2) a. Fill in the table you made with the binary values for
these two numbers (6 and -6), changing the number of bits from
8 to 16, and then to 32.
6
-6
8 bits
16 bits
32 bits
b. Using the applet, change the number size back to 8 bits.
Type in 127 and press Enter. Describe what you see below.
3) a) Now type in -127 to the “Negative binary numbers”
applet and convert. Write down the values. What is the
43. difference between +127 and -127 in 2’s complement form?
b) Perform 38 + (-52) by converting the numbers to binary
and use 8 bits. Write each and every step required to perform
this operation including the 2’s complement conversion.
4) Type 4 into the “number of digits in binary” field. Then
convert the number 8. What do you see? Does this seem right?
How many bits you need to represent 8?
Write down your reasoning and answer:
Exercise 2: Representing Characters
1. Start the “Character codes” applet.
a. Type 100 into the top text area and press “Enter” (or click
on the Convert to Character button). Write down what you see.
b. Type in 68 and do the same. What relation does this
character have to the first one?
c. Do the same for 101 and 69, and for 102 and 70. Write
down the codes and the characters you see.
d. What conclusion can you draw about how upper- and
lowercase characters in ASCII are represented, based on your
experiments?
(HINT:If you are still stuck, fill out this table.)
44. Code
Letter
68
100
69
101
70
102
2. If you were writing an algorithm or formula to capitalize
text for a word-processing program, what simple mathematical
transformation would you make to the character codes to
capitalize a letter?
3. Now type in 232, 233, 234, and 235, one at a time.
a. Write down what you see for each one. (Copy from applet
and paste it here)
232:
233:
234:
235:
b. What characteristics do these characters share?
4. What does ASCII code 241 look like? (Copy from applet
and paste it here)
45. Exercise 3: Text Translator
1. Start the “Text Encoding in ASCII” applet. Type in a short
sentence and press “Enter” or click on “translate text” button.
Paste your screenshot below.
2. Suppose you wrote an essay and your word processor
reported that it contained 10,000 characters. How many bits
would your computer need to store the essay using ASCII
codes? How many bytes is that?
3. Scroll the tall window on the left to see all the ASCII codes.
Write down the numerical codes for these symbols:
__________ ½
__________ ¼
__________ ¾
__________ x (multiplication)
__________ ÷ (division)
__________ ±
Exercise 4: Representing Colors
1. Start the “Color maker” applet.
46. a. Select Yellow from the names choice pull-down menu.
Write down the RGB and HSB values.
RGB:
HSB:
b. Now select Magenta and do the same.
RGB:
HSB:
2. Suppose you heard that Kathy’s favorite color was 0,255,0.
What would Kathy call that color?
3. Pick a color from the pull-down list of names in the center,
and gradually slide the saturation scrollbar toward the top so
that the value in the box below “Sat” goes down to 0. Test
various colors and figure out which color doesn’t change.
4. Pick another color from the pull-down list and gradually
slide the brightness scrollbar toward 0. What color do you end
up with? Is this true of any color?
5. Set 140 into the Red box by scrolling it . Then type 0 into
the green box and press return, and do the same for the blue
box. Take a screenshot of the applet, and paste it here, below
this line:
48. Question 3
6
4
Question 1
2
Question 2
2
Question 3
2
Question 4
2
Question 5
2
Total
40
7
BUSI 645
Group Project Instructions
The purpose of the Group Project is to generate interaction
among students in regard to relevant current course topics with
faith integration. Groups will be assigned by the instructor
based on random selection by Module/Week 4. A minimum
1,000-word essay will be worked on as a group based on the
prompt given.
49. Each group will complete a 1-page project outline and tentative
reference page on an approved topic. The reference page will
contain a minimum of 5 scholarly sources. This assignment
must be in current APA format.
Each group is to select 3 broad course topics (e.g., pay for
performance; person-based versus job-based pay determination;
fair pay). Discuss those topics in light of a biblical worldview.
For instance, consider and discuss pay fairness in relation to the
Christian worldview of fairness.
In addition to the Bible, the essay must include at least 3 other
outside scholarly sources in current APA format (the text may
count as one) to substantiate the group’s position. Each reply
must cite at least 2 sources. Acceptable sources include the
Bible (which is required), the text, and other scholarly sources.
Each paper must be submitted in current APA format with an
introduction and conclusion. It must be presented as though it is
a “whole” paper, well edited, not individually written in parts
and then pieced together.
Individual projects are not allowed. Lack of participation is not
acceptable and will result in a grade of 0. In other words, the
instructor will review levels of contribution in order to
determine individual grades in relation to the group grade.
Submit your outline by 11:59 p.m. on Sunday of Module/Week
5.
The essay must be submitted to SafeAssign and the
corresponding Discussion Board Forum by 11:59 p.m. (ET) on
Thursday of Module/Week 7 by 1 group member. Individual
replies of at least 250 words to 2 other groups must be
submitted by 11:59 p.m. (ET) on Sunday of the same
module/week. The Final version of the group project must be
50. submitted by one member to the group assignment link by 11:59
(ET) on Sunday of week 7.
Criteria Levels of Achievement
Content 70% Advanced Proficient Developing Not present
Content and
development
7 Points
Information clearly relates to
the main topic. It includes
several supporting details
and/or examples. All topics
are thoroughly addressed
and/or all questions are
answered. Minimum word
count is reached.
6 to 5 points
Information clearly relates to
the main topic. No details
and/or examples are given.
All or most topics are
generally but not
51. comprehensively addressed
and all or most questions are
answered. Minimum word
count is reached.
4 to 1 points
Assignment is missing key
elements; lackscontextual
presentation and the central
thesis of the project is unclear.
Information has little or no
relation to the main topic. Topics
and/or questions were not
addressed satisfactorily.
Minimum word count is not
reached.
0 points
No assignment submitted.
Structure 30% Advanced Proficient Developing Not present
Organization and
Sources
3 points
52. Outline is complete. Includes
title, planned sections, and
sample list of 5 scholarly
sources.
2 points
Outline is somewhat complete.
References or planned sections
may be missing.
1 point
The information appears to be
disorganized. Key parts are
missing.
0 points
No assignment submitted
or is posted in question
and answer format.