Notes+12.2

Low Attendance, Review

Stack, Queue, Circular Queue, OrderedCollection

How to compute index in a rectangular matrix.

C's so-called "int" has a bit for sign, the rest of the bits count distance from 0. Note: it is very convenient if (1 -1) = 0,. . . (13 - 13) =0, etc. Thus -1 = 11111111111111111111111111111111111111111111111111111 2 (however many bits there are in your architecture) Since 13 = 1101 2, -13 = 1111111111111111110011 2

tHERE'S SOME VARIANCE ... STUPID MODE-ERROR KEY... I'm at a public computer and don't want to annoy the librarian by popping off the stupid cAPS lOCK key. There's some variance between different hardware architectures, but a floating point number has one bit for the sign, a few bits for the exponent, and many bits for the mantissa. See []

In C, ints are a small subset of the mathematical integers. The sum of two positive ints might not be positive: code format="c" > cat overflow.c
 * 1) include 

main { int num, ix; for(ix=1; ix<36; ix++) { num = num * 2 + 1; printf("%2i: %i\n", ix, num); } }

> overflow 1: 1 2:  3 3:  7 4:  15 5:  31 6:  63 7:  127 8:  255 9:  511 10:  1023 11:  2047 12:  4095 13:  8191 14:  16383 15:  32767 16:  65535 17:  131071 18:  262143 19:  524287 20:  1048575 21:  2097151 22:  4194303 23:  8388607 24:  16777215 25:  33554431 26:  67108863 27:  134217727 28:  268435455 29:  536870911 30:  1073741823 31:  2147483647 32:  -1 33:  -1 34:  -1 35:  -1

code Are there other "fixed point" arithmetic functions? That is, iterate x = f(x) but only in C? Ans: of course! Here's one: code 1: 1 2:  5 3:  21 4:  85 5:  341 6:  1365 7:  5461 8:  21845 9:  87381 10:  349525 11:  1398101 12:  5592405 13:  22369621 14:  89478485 15:  357913941 16:  1431655765 17:  1431655765 18:  1431655765 code And here's another: code 1: 1 2:  17 3:  273 4:  4369 5:  69905 6:  1118481 7:  17895697 8:  286331153 9:  286331153 code And another: code 1: 1 2:  65537 3:  65537 code A puzzler might ask how many such functions there are. A good and mathematically-skilled puzzler would first refine the question.

We could use Polynomials to represent integers. After all, 7036 = 7*10^3 + 0*10^2 + 3*10^1 + 6*10^0

Using our fairly heavy polynomials to store base 10 would be overkill. If we have 32-bit ints, we might use base 2^16, where the "digits" go from 0 to 2^16 -1. That way, even in non-normalized form, a partial product will not overflow.