Welcome to MSDN Blogs Sign in | Join | Help

Computer Science Teacher - Thoughts and Information from Alfred Thompson

Alfred Thompson's blog about teaching computer science at the K-12 level. Alfred was a high school computer science teacher for 8 years. He has also taught grades K-8 as a computer specialist. He has written several textbooks and project books for teaching Visual Basic in high school and middle school. Alfred is the K-12 Computer Science Academic Relations Manager for Microsoft and is trying to be the Microsoft Education Blogger.

Syndication

News


Featured in Education.AllTop.com



TwitterCounter for @alfredtwo




Thinking About Numbers - Decimal, Binary and Roman

One of the things I found to be a little bit scary was how limited the understanding so many high school students had about the nature of numbers. Oh sure they understood the difference between real number and integers and they had a sense of the scale of numbers (what's large? What's small?) but they seemed somewhat uninformed or perhaps lacked understanding of how numbers were formed. let me spell that out. When explaining binary numbers ("This is the ones digit, this is the twos digit, this is the fours digit") it seemed like some students had trouble relating that to the ones, tens and hundreds digit they were used to in decimal. Back in the middle ages when I was a student we learned about different number systems long before I got to high school. It really improved my understanding of how numbers worked.

I remember learning bases 5, 7 add 8 for example. I used to just play with different number bases for the fun of it. Later when I was a computer science student in college base 2 (binary), base 8 (octal) and base 16 (hexadecimal) seemed quite natural to me. Learning the tricks for converting between octal and hexadecimal and binary made it reasonable to think in those number systems. I generally didn't waste time converting back to decimal unless there was a specific need to display numbers for "regular people." I don't see much of that any more. I wonder how many students learn number bases other than ten at all unless they take a computer science course.

Displaying numbers for different applications is where understanding how numbers work really comes into play. There are two projects that I have used to reinforce that sort of thinking. Displaying numbers as text and displaying Roman numbers.

Generally students when presented with the task of converting integers to Roman numerals first think of using If statements. One If statement for each number. This works just fine (more or less) when the range of numbers runs from one to ten. It works much less well for ranges that go into the thousands. I used to require handling any number up to 4999 because numbers above that require horizontal lines about some characters and that would require students to find a way to draw that. Perhaps that would be a nice challenge for some but outside the scope of what I was trying to teach at that point of the semester.

 The big thing I found binary really useful as an OS developer was bit flags. There were lots of activities and status events that could be tracked using binary values - on or off. Back in the day when I was doing this memory was counted in kilobytes not megabytes or gigabites. Using one wrod to keep track of a lot of flags was necessary. For performace reasons you'd even want those values in a register making good use of space even more important.

This is where being able to know what a bit set or bit test operation is all about. This is when knowing that writing a five to a location sets two bits and resets the others and which bits those are. Does every programmer use that sort of knowledge on a regular basis? Probably not. But when you do need that knowledge it is going to be important and you will need to know it well.

One more important thing about understanding numbers is realizing that fractional parts of real numbers are stored as binary and what that means. The most important thing it means is that some numbers that we take for granted in decimal are very different when converted to decimal. For example that .1 is a repeating fraction when converted to binary. The old favorite of having a program make change is great for teaching that lesson the hard way. All too often it seems that lesson takes a  while to sink in though. I have on occasion gone through the exercise of converting decimal fractions into binary but I think I would prefer if some middle school math teacher had done it first so I wouldn't have to.

Lastly I think the most important thing I learned from learning number bases early was that numbers can be fun. In middle school a lot of things can be taught as fun and interesting without trying to impress on students importance that they are not yet ready for. I learned that playing around with numbers could be fun and was very pleased when I later learned that such things were useful as well. While older students tend to demand that education be relevant and useful younger students care at least as much about things being fun. Teaching math (and numbers) as fun while students are young seems like it would be a good thing. It requires teachers who know their stuff very well and enjoy the subject though. That latter part seems to be harder to find all the time though. I have not easy answer for that one.

 

Technorati tags: , , ,

Published Tuesday, January 02, 2007 1:54 AM by Alfred Thompson

Comments

# re: Thinking About Numbers - Decimal, Binary and Roman @ Tuesday, January 02, 2007 12:29 PM

Great post. The whole experience of number representation is great to have.  It also leads to distinction of a powerful abstraction: numerals as different from numbers.  

This gets to the heart of an important stumbling blog for some neophytes: understanding how "'0'" and "0" are different (and perhaps pointing out a pitfall of schemes where they are not -- some of the time).

Dennis E. Hamilton

# re: Thinking About Numbers - Decimal, Binary and Roman @ Wednesday, January 03, 2007 3:09 AM

If someone is interested: I have full VB/VB.NET code to go to and from Roman numbers, and to convert to and from decimal numbers.

The functions for Roman numbers are somewhat buried, so I give them here:

Function romtodec(roman As String) As Integer

Dim buffer As Integer

Dim thisnumber As String * 1

Dim nextnumber As String * 1

Dim number As Integer

Dim p As Integer

For p = Len(roman) To 1 Step -1

thisnumber = UCase(Mid$(roman, p, 1))

Select Case thisnumber

Case "M"

buffer = buffer + 1000

Case "D"

buffer = buffer + 500

Case "C"

If UCase(nextnumber) = "M" Then

buffer = buffer - 100

Else

buffer = buffer + 100

End If

Case "L"

buffer = buffer + 50

Case "X"

If UCase(nextnumber) = "C" Then

buffer = buffer - 10

Else

buffer = buffer + 10

End If

Case "V"

buffer = buffer + 5

Case "I"

If UCase(nextnumber) = "V" Or UCase(nextnumber) = "X" Then

buffer = buffer - 1

Else

buffer = buffer + 1

End If

Case Else

MsgBox "Dit is geen Romeins cijfer"

Exit Function

End Select

nextnumber = thisnumber

Next p

romtodec = buffer

End Function

Function dectorom(decgetal As Integer) As String

Dim buffer As String

Dim restgetal As Integer

Dim test As Integer

If decgetal > 5000 Or decgetal < 1 Then

dectorom = "FOUT"

Exit Function

End If

restgetal = decgetal

'Duizentallen

Do

test = restgetal - 1000

If Not test < 0 Then

buffer = buffer & "M"

restgetal = restgetal - 1000

End If

Loop Until test < 1000

'Negenhonderd

test = restgetal - 900

If Not test < 0 Then

buffer = buffer & "CM"

restgetal = restgetal - 900

End If

'Vijfhonderd

test = restgetal - 500

If Not test < 0 Then

buffer = buffer & "D"

restgetal = restgetal - 500

End If

'Honderd

Do

test = restgetal - 100

If Not test < 0 Then

buffer = buffer & "C"

restgetal = restgetal - 100

End If

Loop Until test < 100

'Vijftig

test = restgetal - 50

If Not test < 0 Then

buffer = buffer & "L"

restgetal = restgetal - 50

End If

'Tientallen

Do

test = restgetal - 10

If Not test < 0 Then

buffer = buffer & "X"

restgetal = restgetal - 10

End If

Loop Until test < 10

'Negen

test = restgetal - 9

If Not test < 0 Then

buffer = buffer & "IX"

restgetal = restgetal - 9

End If

'Vijf

test = restgetal - 5

If Not test < 0 Then

buffer = buffer & "V"

restgetal = restgetal - 5

End If

'Vier

test = restgetal - 4

If Not test < 0 Then

buffer = buffer & "IV"

restgetal = restgetal - 4

End If

'Eenheden

Do

test = restgetal - 1

If Not test < 0 Then

buffer = buffer & "I"

restgetal = restgetal - 1

End If

Loop Until test < 0

'Stop

dectorom = buffer

End Function

and http://hlrnet.com/vbweb/net_talstelsels.htm

Hans Le Roy

# re: Thinking About Numbers - Decimal, Binary and Roman @ Saturday, January 06, 2007 7:06 PM

Binary math is definitely essential when beginning to understand the science behind computers. For some reason, students seem to have trouble with binary math - I attribute it to the fact that they don't learn about number bases in math class.

Anyway, here's a good site for learning the basics. There are also practice problems and a conversion tool that breaks back and forth conversion between the decimal and binary number systems.

http://www.BinaryMath.info

Jason

New Comments to this post are disabled
Page view tracker