$30
CSC 230
1
Lab 1: Number Systems and Introduction to Arduino IDE
Submit lab1.txt at the end of your lab.
I. Lab Environment
Need a card to access the lab. If you have a card, email engrcard@engr.uvic.ca (include the 5-digit
card number and your student number) to set up the card access. If you don’t have a card, you can
purchase it from the bookstore for a non-refundable $10 fee. For card related problems, email.
engrcard@engr.uvic.ca, include the 5-digit card number, student number, the room, the time and
day, and for what course, so that the problem can be solved more quickly.
Tip: if you purchase the card only, you can go to the computer store (inside the bookstore) and
purchase one there to avoid the long line up.
Use your netlink ID and password to log in. Email itsupport@csc.uvic.ca if you have any
difficulties to log on to the machines or to print documents in the labs.
ECS 249 is the only lab with hardware/software provided for this course. The software is also
installed in two drop-in labs ECS 266 and ECS 348 (Window’s machines only) and two other
teaching labs ECS250/258 (when no labs are in session). Suggest you start your assignments early.
“H” drive is your network space on the CSC server. Store all your work in H drive and keep a
back up copy using other portable devices (such as a flash memory or a floppy disk). Files stored
in the C drive might be erased overnight.
For printing, once you send your printing job, use the printers outside. There are two printers: one
on the 2nd floor, and the other is on the 3rd floor, in the study areas. Log in using your netlink ID
and password. If you have credit on your student card, you can release your work. Otherwsie, you
need to add credit to your card.
ECS Outside doors open from 7:30-10:30pm Mon-Fri except holidays. ECS drop-in lab doors are
open business hours starting at 7:30am - 7pm, Mon-Fri except holidays. Outside these hours, card
access only.
It is a busy lab. We share the lab with csc 355 students. Suggest you check the csc 355 course
outline at https://heat.csc.uvic.ca/coview/course/2019091/CSC355. In the weeks when there are no
csc 355 labs, you may use the computers during their lab hours.
II. Number Systems
In the computer system, we need to know how many bits (storage space) are used. For example, let’s
count the number of students in the lab. In decimal number system, we just need two digits. In binary
number system, how many bits do we need? Let’s do counting up in decimal, binary and hexadecimal.
Here is the conversion table (try to be very familiar with or memorize the purple part):
CSC 230 Fall 2019
2
Decimal (2 digits) Binary (5 bits) Hexadecimal (2 digits)
0 0b00000 0x00
1 0b00001 0x01
2 0b00010 0x02
3 0b00011 0x03
4 0b00100 0x04
5 0b00101 0x05
6 0b00110 0x06
7 0b00111 0x07
8 0b01000 0x08
9 0b01001 0x09
10 0b01010 0x0A
11 0b01011 0x0B
12 0b01100 0x0C
13 0b01101 0x0D
14 0b01110 0x0E
15 0b01111 0x0F
16 0b10000 0x10
17 0b10001 0x11
18 0b10010 0x12
19 0b10011 0x13
20 0b10100 0x14
21 0b10101 0x15
22 0b10110 0x16
23 0b10111 0x17
24 0b11000 0x18
III. Test the Arduino Board - Introduction to Arduino IDE 1
- Launch Arduino IDE: click on the Start button, then click on the Arduino program.
CSC 230 Fall 2019
3
Click on the Start button.
Click on the Arduino program.
CSC 230 Fall 2019
4
- The Arduino IDE is launched, go to the menu, click on File -> Examples -> 01.Basics -> Blink.
- Scroll down the source code and change LED_BUILTIN to 52:
- Why change it to 52? It is the pin number on the Arduino board. You will learn more later in the
course. To give you a brief explanation now, see the portion of a diagram of the Arduino board
below. It shows the pins connected to the LED lights. Pin 52 controls the LED light at the bottom.
CSC 230 Fall 2019
5
What does bit 1 mean?
It means at 21
position in a binary system. In order to turn on the LED light at the bottom, the binary
number assigned to PORTB should set the bit 1 to 1. For example, the position of an 8-bit binary number
(1 byte) 0b0000010 is listed below:
bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
0 0 0 0 0 0 1 0
42 – PL7 (Port L, bit 7 - 2
7)
44 – PL5 (Port L, bit 5 – 2
5)
46 – PL3 (Port L, bit 3 – 2
3)
48 – PL1 (Port L, bit 1 – 2
1)
50 – PB3 (Port B, bit 3 – 2
3)
52 – PB1 (Port B, bit 1 – 2
1)
CSC 230 Fall 2019
6
- In the Arduino IDE program, select the right board: go to the menu, click on Tools →Board:
“Arduino/Genuino Uno” → Arduino/Genuino Mega Or Mega 2560.
CSC 230 Fall 2019
7
- Select the right port: go to the menu, click on Tools →Port: “COM1” → COM4
(Arduino/Genuino Mega or Mega 2560). The port number veries among chips. Yours may be
COM3, or COM5 etc.
CSC 230 Fall 2019
8
- Compile your code: go to the menu, click on Sketch →Verify/Compile Ctrl+R. You may use
shortcut keys: press Ctrl key and r (lower case r) key at the same time.
- If no errors, upload your program to the board: go to the menu, click on Sketch →Upload. The
LED light at the bottom blinks. Change 52 to other numbers (42, 44, 46, 48 or 50) and observe the
LED lights.
IV. Exercises
1. Why do we use 5 bits in the table in part II (the number of students attending the lab)? Can we use
only 4-bits instead?
2. How many different values can be represented by 6 bits?
3. There are 194 students registered in CSc 230, what is the minimum number of bits needed to
represent this number in binary (assume it is an unsigned number)?
4. Convert the following numbers:
a. 0b1001101 (unsigned) to decimal
b. 63 to unsigned binary and unsigned hexadecimal
5. Convert the following numbers:
a. -63 to binary (using 2’s complement notation) and then to Hex
b. 0b101011 (2’s complement) to decimal
c. 0b001110 (2’s complement) to decimal
CSC 230 Fall 2019
9
6. What are the minimum and maximum values (in decimal) represented by a 4-bit binary number: a)
as an unsigned number? b) as a signed number (2's complement)? How about 8 bits, 16 bits, k
bits? For example, if it is a 2-bit number:
Number of bits Unsigned Signed
2 [0, 3] [-2,1]
7. What is the result of bit-wise AND operation of: 0b10110010 with 0b11110000?
8. What is the result when bit-wise XOR and mask of 0b11111111 are applied on byte 0b10110100?
9. Recall the position of each bit in an 8-bit number (one byte) is 27
2
6
2
5
2
4
2
3
2
2
2
1
2
0
. What is the 8-bit
binary number x (also called mask) to be used if we want to clear bits at positions 2
2
, 2
3
, 2
5
and 2
7
of an 8-bit (1 byte) binary number n? For example, if n is 0b10100110, after “and” with x, the
result is: 0b00000010. Notice that bits at positions 2
2
, 2
3
, 2
5
and 2
7
are set to 0, and the bits at
other positions are not changed. The questions is: what is the value of x in binary?
Download lab1.txt. Write your answers and submit lab1.txt via conneX. You must click the
“Submit” button. Write your name, student number at the top. Due at the end of your lab.
1. Adapted from the lab notes written by Dr. Bill Bird for csc 230 in the summer of 2018.