flowcharts, modularity, and numbers
inf1339
faculty of information
university of toronto
Image from "Healers of the Wild: People Who Care for Injured and Orphaned Wildlife" by Shannon K. Jacobs, by way of the Wild Bird Fund.
Wake Up
Shower
Eat
Read
M,W,F
Shake
Egg
Make Breakfast
Wake Up
Shower
Eat
Read
M,W,F
Shake
Egg
Make Breakfast
Wake Up
Shower
Eat
Read
M,W,F
Shake
Egg
Make Breakfast
Wake Up
Shower
Eat
Read
Make Breakfast
M,W,F
Shake
Egg
Wake Up
Shower
Eat
Read
Make Breakfast
M,W,F
Shake
Egg
Wake Up
Shower
Eat
Read
M,W,F
Shake
Egg
Make Breakfast
arrow
flow
"go to..."
circle
terminal/connector
"and then..."
diamond
decision/branch
"if this is true..."
rectangle
module/action
"do this"
Control flows INTO THE TOP and OUT OF THE BOTTOM of rectangles.
Control flows INTO THE TOP and OUT THE SIDES of diamonds.
Control can flow INTO THE TOP, IN FROM THE LEFT, or both IN FROM and OUT TO THE SIDES of a connector circle.
Entry Circle
Exit Circle
Zero or
more
MODULES
module
action
module
condition
module
condition
module
condition
module
module
action
action
action
action
module
action
action
action
action
module
module
condition
module
condition
module
module
condition
module
condition
module
condition
module
module
condition
module
module
module
condition
module
module
condition
module
condition
module
module
condition
module
condition
module
condition
This can be a single action or any combination of sequence and contingency.
MODULE: any chunk of activity that can be popped into or out of a flowchart because of its single entry single exit property.
MODULE
condition
A
do action
B
do action
C
if condition A
do action B
else
do action C
the diamond splits the
flow into branches
the circle rejoins the
branches into a single exit
condition
A
do action
B
do action
C
if condition A
do action B
else
do action C
condition
A
do action
B
do action
C
if condition A
do action B
else
do action C
While it is raining, keep your umbrella up.
Keep your umbrella up until it stops raining.
While it is raining, use an umbrella.
If it is raining, use an umbrella, if not, put the umbrella away. Check every few minutes to see if it is still raining.
Is it raining?
Yes? Use an umbrella
Check again
Put the umbrella away
raining?
use umbrella
put umbrella away
WHILE A DO B
A?
B
YES
NO
SINGLE EXIT POINT
SINGLE ENTRY POINT
Use an umbrella. Check every few minutes to see if it is still raining. When it stops, put the umbrella away.
Use an umbrella
Check for rain
If no rain, proceed.
Put the umbrella away
use umbrella
put umbrella away
Keep your umbrella up until it stops raining.
stopped raining?
REPEAT B UNTIL A
A?
B
SINGLE EXIT POINT
SINGLE ENTRY POINT
NO
YES
In a WHILE loop, the "action" may be executed ZERO OR MORE TIMES
In an UNTIL loop, the "action" is always executed AT LEAST ONCE (i.e., "one or more times")
If today is Tuesday, we must be in Belgium
Tuesday?
Belgium
YES
DO A. IF B, DO C, otherwise DO D. DO E. DO F.
B
A
E
F
C
D
YES
NO
IF B
DO C
OTHERWISE D
IF B,
DO C,
otherwise DO D.
DO A. IF B, DO C, otherwise DO D. DO E. DO F.
B
A
E
F
C
D
YES
NO
IF B
DO C
OTHERWISE D
IF B,
DO C,
otherwise DO D.
How to find wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
wildlife rehab
fledgling
Y
Y
Y
Y
Y
Y
Y
Y
How to find wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
wildlife rehab
fledgling
Y
Y
Y
Y
Y
Y
Y
Y
How to find wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
wildlife rehab
fledgling
Y
Y
Y
Y
Y
Y
Y
Y
How to find wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
wildlife rehab
fledgling
Y
Y
Y
Y
Y
Y
Y
How to find wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
wildlife rehab
fledgling
Y
Y
Y
Y
Y
Y
Y
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
How to find wildlife rehab
wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
wildlife rehab
How to find wildlife rehab
wildlife rehab
How to find wildlife rehab
hurt or sick?
feathered?
nestling
intact?
see nest?
safe?
put in nest
parents?
make nest
put in nest
parents?
leave
leave
put in bushes
parents?
leave
wildlife rehab
wildlife rehab
leave
wildlife rehab
fledgling
Y
Y
Y
Y
Y
Y
Y
wildlife rehab
wildlife rehab
I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions: Scrub until clean. Rinse until clear. Inspect. If not OK, start over.
Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside
I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions:
Scrub until clean. Rinse until clear. Inspect. If not OK, start over.
Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside
scrub
until clean
rinse
until clear
inspect
if OK, done
else, start over
repeat
repeat
scrub
until clean
repeat
rinse
until clear
inspect
until OK
I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions:
Scrub until clean. Rinse until clear. Inspect. If not OK, start over.
Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside
I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions:
Scrub until clean. Rinse until clear. Inspect. If not OK, start over.
Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside
Q2. What is your gender?
Female
Male
Q2. What is your gender?
Female
Male
Q3. Which category are you in?
Canadian
Student
Climate Change Denier
Big Fan of Teddy Bears
action A
action B
action C
green hair/fur/feathers?
2 legs?
action A
action A
action B
action B
action C
action C
action C
Flowcharts describe DETERMINISTIC processes
At any decision point the condition can be evaluated and one branch or another can be chosen.
Our convention of requiring decisions to be based on YES-NO or TRUE FALSE conditions ensures that branches are mutually exclusive.
How to proceed at an intersection: right or left
Secret codes: if the text contains the word "bread," launch the app; if the text contains the phrase "bread and roses," don't launch the app; if the text contains the word "roses," shut the system down.
Compute X. If X is greater than 0 and less than 12, start program A; if X is greater than 10, launch program B. If X = 11, launch program C.
What to order? If you are hungry and thirsty, order a hot dog and a beer; if you are hungry but not thirsty, order a pretzel; if you are thirsty, order a cola.
If you are over 40 you can sign up for a vaccine in May. If you are under 30 you can sign up for a vaccine in June. If you are in an at-risk category you can sign up now.
Ordinary Deck of Cards. Choose one card at random. Which statement are exhaustive, which are muutlly exclusive?
"you chose a red card" and "you chose a black card"
"you chose a 'face' card" and "you chose an ordinary card"
"you chose a heart," "you chose a club," and "you chose a diamond"
"your card is a number card," "your card is red", "your card is clubs,"
"your card is spades"
"you chose a red card" and "you chose a seven"
EX
ME
EX
ME
EX
ME
EX
ME
EX
ME
condition A
condition C
condition C
condition C
condition C
S
T
U
V
W
X
Y
Z
condition B
condition B
CL01 Binary: Concept of base 2; notation; count to 10; dec2bin, bin2dec; first 10 powers of 2; binary arithmetic
CL02 Hexadecimal: Concept of base 16; notation; hex2bin, bin2hex, hex2dec; ASCII encoding; URL encoding; HTML color encoding
CL03 Counting by Powers: exponents, graphing, logarithms
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010
Start with decimal number, "D"
Divide by 2.
Note the result.
Write down the remainder.
Repeat process with the result.
Continue until nothing left.
D=6
divide by 2
result = 3, remainder = 0
divide by 2
result = 1, remainder = 1
divide by 2
result = 0, remainder = 1
610 = 1102
Start with decimal number, "D"
Divide by 2.
Note the result.
Write down the remainder.
Repeat process with the result.
Continue until nothing left.
call decimal number D
divide D by 2
write remainder R to L
replace D with result
result=0?
read remainders
123 /2 = 61 R1
61 /2 = 30 R1
30 /2 = 15 R0
15 /2 = 7 R1
7 /2 = 3 R1
3 /2 = 1 R1
1 /2 = 0 R1
1
0
0
1
1
1
1
1
1
0
1
1
1
1
1
2
0
32
64
16
8
7777 / 2 = 3888 R1
3888 / 2 = 1944 R0
1944 / 2 = 972 R0
972 / 2 = 486 R0
486 / 2 = 243 R0
243 /2 = 121 R1
121 /2 = 60 R1
60 /2 = 30 R0
30 /2 = 15 R0
15 /2 = 7 R1
7 /2 = 3 R1
3 /2 = 1 R1
1 /2 = 0 R1
1
0
0
0
0
1
1
0
0
1
1
1
1
7777 / 2 = 3888 R1
3888 / 2 = 1944 R0
1944 / 2 = 972 R0
972 / 2 = 486 R0
486 / 2 = 243 R0
243 /2 = 121 R1
121 /2 = 60 R1
60 /2 = 30 R0
30 /2 = 15 R0
15 /2 = 7 R1
7 /2 = 3 R1
3 /2 = 1 R1
1 /2 = 0 R1
1
0
0
0
0
1
1
0
0
1
1
1
1
4096 + 2048 + 1024 + 512 + 64 + 32 + 1
An earlier question asked how we might count if we had 8 fingers, four on each hand, and we came up with the idea that we would only need the digits 0, 1, 2, 3, 4, 5, 6, and 7.
STOP+THINK: But what if we had 8 fingers on EACH hand? How would we count?
When we were counting by something LESS than ten, we simply left some of the usual digits out of the picture. If we lived in a base-8 world (where we had 8 fingers) the digits 8 and 9 would just be silly and unnecessary symbols. If we lived in that world and wanted to think about the imaginary world in which we had ten fingers and so would count by ten we'd need two extra symbols after 7. We could pick any at all. Maybe 0,1,2,3,4,5,6,7,X,Q,10.
So, what if we were counting by sixteen? Then we'd need another 6 symbols and we'd count like this
1, 2, 3, 4, 5, 6, 7, 8, 9, SYMBOL1, SYMBOL2, SYMBOL3, SYMBOL4, SYMBOL5, SYMBAL6, 10
What if we decided to use the first six letters as the symbols? Then we'd have
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 |
1010 | 1110 | 1210 | 1310 | 1410 | 1510 | 1610 |
And this is precisely how we do it in the base 16 or "HEXADECIMAL" number system. It turns out that hexadecimal is particularly useful as a counterpart to binary. For many reasons, but one we'll start with is that the number of values that can be represented with four binary digits is sixteen (think about it: 00002 = 010, 11112 = 1510). So, one shorthand for binary is to represent every four binary digits with a single hexadecimal digit.
Try the examples below. Match each binary number with its hexadecimal equivalent.
1
2
3
4
5
6
64 63 62 61 60
1296 216 36 6 1
3246 = 3*36 + 2*6 + 4*1 = 108 + 12 + 1 = 12110
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
1010 = 10
1011 = 11
1100 = 12
1101 = 13
1110 = 114
1111 = 15
24 23 22 21 20
16 8 4 2 1
164 163 162 161 160
65536 4096 256 16 1
3 x 163 + 10 x 162 + 15 x 161 + 7 x 160
3 x 4096 + 10 x 256 + 15 x 16 + 7 x 1
12288 + 2560 + 240 + 7
15095
FF
111
2000
ACE
C0DE
1000
=15*16+15=25510
=256+16+1=27310
=2*4096=819210
=10*256+12*16+14 =2560+206=276610
=12*4096+13*16+14
=4937410
=409610
162=256 163=4096
Click for solutions
1011010101010111101010101010
1011 0101 0101 0111 1010 1010 1010
B 5 5 7 A A A
{
1011010101010111101010101010
1011 0101 0101 0111 1010 1010 1010
B 5 5 7 A A A
{
American Standard Code for Information Interchange
4465636F 64652074 68697320 41534349 49207465 787460
subscripts: 15916 159hex 159h
prefix: 0x1F9
special characters in URLs as hex pairs prefixed with %
characters in XML and HTML as hex pairs with ode;
colors in HTML & CSS: 3 hex pairs* (red, green and blue) prefixed with #
http://www.example.com/name%20with%20spaces
’ = character U+2019 (’).
This Orange = #FFAA33
*CSS allows 3-hex digit abbreviation, one per component: #FA3 = #FFAA33.
#17e71e
#abcdef
#8800FF
Which color is
#17e71e
#abcdef
#8800FF
Text
N.B. 16110 = 0xA1
1
+1
10
0 + 0 = 0
0 + 1 = 1
1 + 1 = 10
10 + 1 = 11
10 + 10 = 100
1
+0
01
0
+1
01
0
+0
00
1
+1
10
A
+B
WX
A B W X
1 1 1 0
1 0 0 1
0 1 0 1
0 0 0 0