The "anagram" function on page 153 shows an interesting trick.
Section 5.2 describes the floating point types: float, double, and so on. Here you need to remember that floating point notation is slower and less accurate than integer notation. On the other hand it covers a much wider range of possibilities. And as the numbers get bigger, so do the rounding errors! Notice the word 'mantissa' and 'exponent'.
The last section in this piece -- 5.3 describes the sizeof operator. Notice the lake of a space
between 'size' and 'of'. It is not that important in CS201. It is worth noting the
trick for calculating number of elements in an array on page 157. It is subtle and works.
5.1 Integer Types
5.1.1 How integers are stored in a computer
Binary
notation.
5.1.2 Predefined Integer types -- unsigned short long int char
page 153 -- anagram
Cunning trick....
5.2 Floating-point types
5.2.1 Storing real numbers in computers
5.2.2 Predefined floating-point types -- float double long double
5.3 The sizeof operator
How to calculate the number of elements in an array:
sizeof f / sizeof f[0]
. . . . . . . . . ( end of section Reading) <<Contents | End>>
Jargon and Glossary
What predefined data types are most useful in CS201
Which predefined data types will we actually be using
Use int to count and scan, use double for measurements, and strings+chars
for non-numeric data.
How does a computer work
A computer has a control unit(think: dumb brain), an arithmetic-Logical Unit (ALU)
(think: calculator),
primary memory(think: working space), secondary memory(think: file cabinet), and input/output(think: in and out trays).
The primary memory is divided into numbered memory cells each holding one byte of information.
A control unit has a program counter (PC) that counts instructions
and follows the Van Neuman cycle:
The <limits.h> or <climits> library does something similar for chars and its.
By the way, these days all CPUs are using the IEEE Standard floating point notation (ANSI/IEEE Std 754-1985) which defines the limits and precisions.
Notice: all computation is limitted by the ammount of memory available.
What is the purpose of the sizeof operator
It tells you how many bytes the compiler has given to a variable
or to a data type. The lab will give you many examples...
.
How do bits store information
A bit can be made to stand for a single true/false or 1/0 decision.
Two bits can handle four different cases. All we need to do is to decide what each combination means. Similar 8 bits can handle 8 different meanings. Here is how we would make them encode unsigned and signed numbers and as Days of the week:
| Bits | Unsigned # | Signed # | Day of Week |
|---|---|---|---|
| 000 | 0 | 0 | Sun |
| 001 | 1 | 1 | Mon |
| 010 | 2 | 2 | Tue |
| 011 | 3 | 3 | Wed |
| 100 | 4 | 4 | Thu |
| 101 | 5 | -3 | Fri |
| 110 | 6 | -2 | Sat |
| 111 | 7 | -1 | ERROR |
The information has to be encoded as data. In effect we give each bit a particular meaning. We usually do it character by character. But good examples include the UPC code or the International codes for Airports.
Exercise: work out a one letter code for the days of the week.
Exercise: work out a two letter code for the months.
Who put bhinary code together
I think it was Liebnitz in the 1600's.
How are letters changed to binary
When you tap a letter on the key board a particular set of contacts is made.
The ASCII code specified that 'A' was 01000001 and that B would be next... and so on upto 'Z', 'a' starts with 01100001, and so on upto 'z'.
It was a committee decision by the American Standards people.
Does every key on the keyboard have a special number
The main keyboard A-Z0-9....{}[];:....!@#$... are all one byte
ASCII numbers. The arrow and function keys use a sequence of
2,3, or 4 one byt codes developed by ANSI...
Does the operating system determine the word size -- Vista comes in 32-bit and 64-bit versions
I think that this indicates the size of an address in programs running under
the operating system. I don't think it changes the ammount of data the CPU
handles in one cycle. I think that the sizeof operator may well give
the same sizes, for example, whatever the operating system is.
Why are there 8 different predefined data types
This is how C evolved.
The book doesn't mention some of them like wchar (wide character).
What is the method used to store positive and negative numbers
It is called twos-complement... The Wikipedia article
[ Two's_Complement ]
is a good description of hiw it all works and why.
Is there a negative unsigned data type
No. Not really needed. You just write the code with a normal
unsigned number and imagine it is negative as you write the
code.
Can you give a good example that will help with the next quiz
Who said that the next quiz depended on data types?
When is void used
We put void in a function definition to idicate it doe not
retrun any reliable data.
The is another use, the infamous 'void*' which may mention
but leave for CS202 to explain in detail.
Can you write a program to search a MS Excel spreadsheet for data and take you to it
Probably. I've done searches like this in other spreadsheets.
What does bool mean
The keyword bool is short for Boolean, which refers to the name of
George Boole. This link
[ Boolean ]
into the Wikipedia will lead you to more than you need to know
about things Boolean.
In what ways can pointers be used....
Next time
[ 13.html ]
. . . . . . . . . ( end of section Questions) <<Contents | End>> .Next -- Quiz 6 Lab 7 Project 5 [ projects.html#P5 ] [ 13.html ] [ lab06/ ]