diff --git a/_posts/2020-04-02-rsa3.md b/_posts/2020-04-02-rsa3.md index eed7d85..9046828 100644 --- a/_posts/2020-04-02-rsa3.md +++ b/_posts/2020-04-02-rsa3.md @@ -83,7 +83,7 @@ The two biggest "implementations" of public-key cryptography vary only in the ma and how the numbers are ["trapdoored"](https://en.wikipedia.org/wiki/Trapdoor_function) to decrypt if you have the correct key. I will discuss the differences in approach here. -If you want to skip to the next article where I show you how to encrypt your own documents using RSA, see [this link](/2020/04/06/rsa4.html). +If you want to skip to the next article where I show you how to encrypt your own documents using RSA, see [this link](/2020/04/06/rsa4/). ### RSA diff --git a/_site/2020/04/02/rsa3/index.html b/_site/2020/04/02/rsa3/index.html index 388e557..c2a341e 100644 --- a/_site/2020/04/02/rsa3/index.html +++ b/_site/2020/04/02/rsa3/index.html @@ -116,7 +116,7 @@ If you trust nothing and no one, this is your perfered method of security.

and how the numbers are “trapdoored” to decrypt if you have the correct key.

I will discuss the differences in approach here. -If you want to skip to the next article where I show you how to encrypt your own documents using RSA, see this link.

+If you want to skip to the next article where I show you how to encrypt your own documents using RSA, see this link.

RSA

diff --git a/_site/feed.xml b/_site/feed.xml index 542650e..49b4149 100644 --- a/_site/feed.xml +++ b/_site/feed.xml @@ -1,4 +1,4 @@ -Jekyll2021-09-22T08:19:13-06:00/feed.xmlHow To Produce Semantically Correct MathML From XaTeX/LaTeX (and other accessibility ideas)2021-09-18T00:00:00-06:002021-09-18T00:00:00-06:00/2021/09/18/how-to-generate-proper-content-mathml-from-katex-or-latex<p>During a recent run-in with the Simon Fraser Fraser University accessibility department, +Jekyll2021-09-22T11:33:06-06:00/feed.xmlHow To Produce Semantically Correct MathML From XaTeX/LaTeX (and other accessibility ideas)2021-09-18T00:00:00-06:002021-09-18T00:00:00-06:00/2021/09/18/how-to-generate-proper-content-mathml-from-katex-or-latex<p>During a recent run-in with the Simon Fraser Fraser University accessibility department, I learned that they’re writers are so well-trained as to write “image” where a simple diagram is shown, and “print out picture of output” where a piece of code lies. I figure the geniuses over there could use some help creating files for the visually impaired. diff --git a/_site/melody/cmpt-225/01/01-intro/index.html b/_site/melody/225/01-intro/index.html similarity index 100% rename from _site/melody/cmpt-225/01/01-intro/index.html rename to _site/melody/225/01-intro/index.html diff --git a/_site/melody/cmpt-225/02/02-stacks-and-queues/index.html b/_site/melody/225/02-stacks-and-queues/index.html similarity index 100% rename from _site/melody/cmpt-225/02/02-stacks-and-queues/index.html rename to _site/melody/225/02-stacks-and-queues/index.html diff --git a/_site/melody/cmpt-225/01/01-intro.html b/_site/melody/cmpt-225/01/01-intro.html deleted file mode 100644 index 5c16f35..0000000 --- a/_site/melody/cmpt-225/01/01-intro.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - | tait.tech - - - - -
-
-

CMPT 225 - Introduction

- -

CMPT: 225, D100 — Data Structures & Programming

- -

Graded Work

- -
    -
  • 4 Assignments, 32% -
      -
    • Programming & Written Components
    • -
    • Programs: -
        -
      • In C++
      • -
      • running on ESIL Linux machines
      • -
      • using command line tools
      • -
      -
    • -
    -
  • -
  • 3 Tests, 33% -
      -
    • In class
    • -
    -
  • -
  • 1 Final Exam, 35%
  • -
- -

Lectures

- -
    -
  • Slides + audio recording will be posted after lectures.
  • -
- -

Labs

- -
    -
  • There are help times (first labs are next week)
  • -
- -

Instructor Office Hours

- -
    -
  • Will be primarily online — times TBA.
  • -
- -

Instructor Contact

- -
    -
  • Via Canvas or email (for email: write from your SFU account, use subject “225: …”)
  • -
- -

Some Basic Rules

- -
    -
  • In class, do not distract others.
  • -
  • In class, no taking photos/videos/recording
  • -
  • Help each other, but submit your own work.
  • -
  • Masks are mandatory in class: -
      -
    • may be removed while asking a question
    • -
    • if you cannot wear a mask, please email me
    • -
    -
  • -
  • Please stay on “your” side of the table -
      -
    • and stay 6’ away if you don’t have a mask on
    • -
    -
  • -
- -

Course Content

- -
    -
  • Algorithms: processes that operate on data
  • -
  • Programs: implementations of algorithms
  • -
  • Data in programs: stored in data structures -
      -
    • simple D.S.: variables
    • -
    • most algorithms required compound D.S.s: e.g. arrays, lists, …
    • -
    • most non-trivial applications require non-trivial D.S.s
    • -
    -
  • -
  • Data Type: collection of values + operations on these values
  • -
  • Multiple data types: -
      -
    • Cleaner/simpler slg. design
    • -
    • better code
    • -
    -
  • -
  • Abstract Data Type: defined by values + operations without reference to how things are implemented
  • -
  • ADTs provide an abstract view of data: -
      -
    • let us reason about algorithms at a high level, ignoring implementation details
    • -
    -
  • -
  • Good ADT choices reduce program complexity & increase likelihood of success ( which is good).
  • -
  • a[i] vs. a(i)
  • -
- -

We will look at:

-
    -
  • fundamental ADTs
  • -
  • fundamental data structures (to implement them)
  • -
  • sorting algorithms
  • -
  • with attention to: -
      -
    • correctness
    • -
    • efficiency/speed
    • -
    • how to implement
    • -
    • how to choose (for an application)
    • -
    -
  • -
- -

Pre-regs:

- -
    -
  • Basic Programming (e.g. CMPT 125)
  • -
  • Discrete Math (e.g. MACM 101)
  • -
- -

(students get these in many different ways)

- -

To Do

- -
    -
  • Read chapters 1 + 3 of text
  • -
  • Lear about CSIL
  • -
- -

End

- -
-
-
-
- - diff --git a/_site/melody/cmpt-225/02/02-stacks-and-queues.html b/_site/melody/cmpt-225/02/02-stacks-and-queues.html deleted file mode 100644 index 1afdc81..0000000 --- a/_site/melody/cmpt-225/02/02-stacks-and-queues.html +++ /dev/null @@ -1,864 +0,0 @@ - - - - - | tait.tech - - - - -
-
-

Stacks & Queues - 1

- -

CMPT 225, Fall 2021, Lecture 2

- -

Stack

- -
    -
  • ADT that stores a collection of objects/values
  • -
  • Insertions and removals follow last-in-first-out pattern
  • -
  • Fundamental Operations: -
      -
    • push: inserts an element on the “top”
    • -
    • pop: removes + returns the top element
    • -
    -
  • -
- -

e.g.

- - - - - - - - -
Stack indexValue
- -

push a

- - - - - - - - - - - - -
Stack indexValue
0a
- -

push b

- - - - - - - - - - - - - - - - -
Stack indexValue
0b
1a
- -

push c

- - - - - - - - - - - - - - - - - - - - -
Stack indexValue
0c
1b
2a
- -

pop

- - - - - - - - - - - - - - - - -
Stack indexValue
0b
1a
- -
    -
  • conventient optional operations -
      -
    • size: return # of elements on stack // encapsulation
    • -
    • empty: check for emptiness // better than “size=0?”
    • -
    • top: return top element, but don’t remove it // better than x = pop(); push(x) then use x
    • -
    -
  • -
- -

Algorithm Applications

- -
    -
  • parasing/evaluation/transformation of expressions
  • -
  • speech recognition coding/decoding
  • -
  • shared network access control
  • -
  • programming languages & execution -
      -
    • Postscript, Forth, the call stack
    • -
    -
  • -
  • things we do daily with computers
  • -
- -

Parenthasies Checking

- -

Parenthasies: (()(((()())()()(()))

- -

A diagram showing: -For every left parenthasies, add one to a counter. -For every right parthenthasies, remove one from the counter. -If the counter is not zero by the end of the sequence, there are too many on one side of the parenthasies.

- -

Can be done by counting unmached left parenthasies:

- -

Successful example:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCounter
 0
(1
(2
)1
(2
(3
)2
)1
)0
Yay!0
- -

Failed example:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCountry
 0
(1
(2
)1
(2
)1
 Oh no it’s not zero!
- -

Another fail:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCounter
 0
(1
)0
(1
)0
)-1
 Negative 1 this time!
- -

Do this one yourself:

- - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCounter
( 
) 
) 
( 
- -

But consider multiple grouping symbols: (\{\{), (\{)\{, (\{[( ... ]. -Counting is not enough.

- -

Parenthasies Checking

- -

Diagram showing failure on the last character of this sequence: (()((()()))()(())))

- -

Can be done by counting unmatched left parenthasies:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCounter
(1
(2
)1
(2
(3
)2
)1
)0
- -

Example 2:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCounter
(1
(2
)1
(2
)1
- -

Example 3:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCounter
(1
)0
(1
)0
)-1
- -

Example 4:

- - - - - - - - - - - - - - - - - - - - - - - - -
CharacterCounter
(1
)0
)-1
(0
- -

But consider multiple grouping symbols:

- -
    -
  • sequence (\{\}) will and should work
  • -
  • sequence (\{)\} will work and should not
  • -
  • sequence (\{[( ... ???
  • -
- -

Counting is not enough.

- -

Stack-based Algorithm for Checking Grouping Symbols

- -

Pseudo-code:

- -
I is an input stream of symbols.
-S is a new empty stack.
-
-while there are signals to read from I {
-  c is next symbol from I
-  if c is a left grouping signal {
-    push c on S
-  } else if c is a right grouping signal{
-    if s in empty { report error and stop }
-    d is pop S
-    if c and d do not match { report error and stop }
-  endif // if c is not a grouping symbol, ignore it
-end while
-
-if S is not empty { report error and exit }
-report ok
-
- -

Diagram showing how each set of parenthasies are matched, innermost first torwards the outermost.

- -

Stack: Partially-Filled Array Implementation

- -

Variables:

- -
    -
  • A - an array of stack elements
  • -
  • capacity - size of array
  • -
  • top - index in array of top stack element -
      -
    • -1 if stack is empty
    • -
    -
  • -
- -

A starts out as:

- - - - - - - - - - - - - - - - - - - - -
Index012capacity-1
Valueabc 
- -
    -
  • Capacity = <size of A>
  • -
  • top = 2
  • -
- -

push e

- -

A now equals

- - - - - - - - - - - - - - - - - - - - - - - - -
Index01234capacity-1
Valueabcde 
- -
    -
  • capacity = <size of A>
  • -
  • top = 3
  • -
- -

The Queue ADT

- -

A container that stores a collection of items with insertion and removal in “first-in-first-out” order.

- -

Stack: a digram showing circled being placed on top of eachother, pushing circles into the tube, then popping them out from the same size (the top). Like a pringles can of elements.

- -

Queue: a diagram showing circles being unqueued in on the left and dequeued on the right. Like waiting in line for food.

- -

Basic operations:

-
    -
  • enqueue: add an item to the back of a list
  • -
  • dequeue: remove & return the item at the front of the list
  • -
- -

Example: Palindrome Checking

- -

Sequence aba should succeed. -Sequence aab should not.

- -

In an array: a diagram showing the following pattern with the variable i set to the leftmost element and j set to the rightmost element.

- - - - - - - - - - - - - - -
Valuesabcsba
- -

With a stack and queue:

-
    -
  1. read symbols, starting each in a stack and a queue
  2. -
  3. while the stack, queue are not empty: -
      -
    • pop and element from the stack + delete an element from the queue
    • -
    • if different -> not a palindrome
    • -
    -
  4. -
  5. palindrome
  6. -
- -

Queue: Array Implementations

- -

Enqueue: a,b,c,d. -Front is now a, last is now d.

- - - - - - - - - - - - -
Valuesabcd
- -

Dequeue returns and deletes first element. -Front is now b, last is now d.

- - - - - - - - - - - - -
Values?bcd
- -

Many enquques/dequeues later:

- - - - - - - - - - - - -
Valuessmno
- -

Front element is now m, last element is now s.

- - - - - - - - - - - - - -
Values?tuvw
- -

A similar slide is here, but I can’t see the differnece.

- -

Variables:

-
    -
  • array A is array of size capacity
  • -
  • front is 0
  • -
  • back is 0
  • -
  • size is 0
  • -
  • capacity = <size of array>
  • -
- -

Pseudo-code:

- -
array A = array of size capacity // holds queue contents
-front = 0 // index in A of front element, if queue not empty
-back = 0 // index where next unqueued element will go
-size = 0 // number of elements in queue
-capacity = <size of array> // ???(can't read) queue size supported
-
-enqueue(x) { // adds x to the back of the queue
-  // requires size<capacity>
-  A[back] = x
-  size = size + 1
-  back = (back + 1) % capacity
-}
-
-dequeue() { // removes front element of queue and returns it
-  // required size > 0
-  temp = A[front]
-  front = (front + 1) % capacity
-  size = size - 1
-  return temp
-}
-
- -

Is size == front - back?

- -

Diagram showing only true if front and back haven’t been switched around due to wrapping around back to the beginning o the array.

- -

“Circular Array” Queue Example

- -
    -
  • size = 0
  • -
  • front = 0
  • -
  • back = 0
  • -
- - - - - - - - - - - - - -
Valuesemptyemptyemptyemptyemptyempty
- -

enqueue: a,b,c,d

- -
    -
  • front = 0
  • -
  • back = 4
  • -
- - - - - - - - - - - - - -
Valuesabcdemptyempty
- -

dequque 3 times

- -
    -
  • front = 3
  • -
  • back = 4
  • -
- - - - - - - - - - - - - -
Valuesemptyemptyemptydemptyempty
- -

enqueue e,f,g,h

- -
    -
  • front = 3
  • -
  • back = 2
  • -
- - - - - - - - - - - - - -
Valuesghemptydef
- -

unqueue j

- -
    -
  • size = 6
  • -
  • font = 3
  • -
  • back = 3
  • -
- - - - - - - - - - - - - -
Valuesghjdef
- -

dequeue 3 times

- -
    -
  • back = 3
  • -
  • front = 0
  • -
- - - - - - - - - - - - - -
Valuesghjemptyemptyempty
- -

dequeue 3 times

- -
    -
  • back = 3
  • -
  • front = 3
  • -
- - - - - - - - - - - - - -
Valuesemptyemptyemptyemptyemptyempty
- -

End

- -
-
-
-
- - diff --git a/_site/melody/cmpt-225/03/03-memory-and-pointers.html b/_site/melody/cmpt-225/03/03-memory-and-pointers.html deleted file mode 100644 index 0e7cb60..0000000 --- a/_site/melody/cmpt-225/03/03-memory-and-pointers.html +++ /dev/null @@ -1,168 +0,0 @@ - - - - - | tait.tech - - - - -
-
-

Memory & Pointers 1

- -

CMPT-225, Fall 2021

- -

Computer Memory

- -
    -
  • A sequence of locations
  • -
  • Indexed by address: 0,1,2,…
  • -
  • Each location stores a data byte
  • -
  • Processor can read or write the byte at each address.
  • -
  • Regions of memory are allocated to processes as needed, according to some scheme.
  • -
- -

Diagram displaying “Code + Data for running part of OS” at the start of memory, “Free memory” in the middle, and “Code + Data for running user processes” and the end.

- -

Variables & Memory

- -

A variable is (roughly) and names & tagged collection of bytes:

- -

Diagram showing:

-
    -
  • “int x; x = 6” taking 4 bytes of memory,
  • -
  • “char c; c = ‘x’;” taking 1 byte of memory
  • -
  • -

    “bool b; b = ‘true’;” taking 1 byte of memory

    -
  • -
  • So, at run time, each variable has an address in memory.
  • -
  • In C, C++ we can: -
      -
    • access the address of a variable
    • -
    • access a variable or memory location by its address
    • -
    • declare variables by storing addresses (pointers).
    • -
    -
  • -
- -

Addresses & Pointers - By Example

- -
    -
  • “int i = 5;” -
      -
    • allocate space for an int,
    • -
    • name the space “i”,
    • -
    • store 5 there
    • -
    -
  • -
  • “int *p;” -
      -
    • allocate space for an address,
    • -
    • name it p,
    • -
    • record its type as “pointer to int”
    • -
    -
  • -
  • “p = ∧i;” -
      -
    • “&i” is the address of “i”
    • -
    • store ∧i in p
    • -
    • so, p becomes a pointer to i
    • -
    -
  • -
  • “cout « i;” -
      -
    • outputs the value stored in i, 5
    • -
    -
  • -
  • “cout « p;” -
      -
    • outputs the address of i: 0xbffffbbc
    • -
    -
  • -
  • “cout « *p;” -
      -
    • ”*” dereferences p. That is, *p is the value pointed to by p. In this case 5
    • -
    -
  • -
- -

Diagram of memory:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressNameValue
254i5
923p254
- -

Second diagram of memory:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressNameValueSize
0x6fffbei54 bytes
???p0x6fffbe4 bytesa
- -

Slide showing program code: see pointers.c

- -

Slide showing output: see output.txt

- -

Slide showing same program with different highlights.

- -

Slide showing same output with different highlights.

- -

End

- -
-
-
-
- - diff --git a/_site/melody/cmpt-225/03/03-memory-and-pointers/index.html b/_site/melody/cmpt-225/03/03-memory-and-pointers/index.html deleted file mode 100644 index 0e7cb60..0000000 --- a/_site/melody/cmpt-225/03/03-memory-and-pointers/index.html +++ /dev/null @@ -1,168 +0,0 @@ - - - - - | tait.tech - - - - -
-
-

Memory & Pointers 1

- -

CMPT-225, Fall 2021

- -

Computer Memory

- -
    -
  • A sequence of locations
  • -
  • Indexed by address: 0,1,2,…
  • -
  • Each location stores a data byte
  • -
  • Processor can read or write the byte at each address.
  • -
  • Regions of memory are allocated to processes as needed, according to some scheme.
  • -
- -

Diagram displaying “Code + Data for running part of OS” at the start of memory, “Free memory” in the middle, and “Code + Data for running user processes” and the end.

- -

Variables & Memory

- -

A variable is (roughly) and names & tagged collection of bytes:

- -

Diagram showing:

-
    -
  • “int x; x = 6” taking 4 bytes of memory,
  • -
  • “char c; c = ‘x’;” taking 1 byte of memory
  • -
  • -

    “bool b; b = ‘true’;” taking 1 byte of memory

    -
  • -
  • So, at run time, each variable has an address in memory.
  • -
  • In C, C++ we can: -
      -
    • access the address of a variable
    • -
    • access a variable or memory location by its address
    • -
    • declare variables by storing addresses (pointers).
    • -
    -
  • -
- -

Addresses & Pointers - By Example

- -
    -
  • “int i = 5;” -
      -
    • allocate space for an int,
    • -
    • name the space “i”,
    • -
    • store 5 there
    • -
    -
  • -
  • “int *p;” -
      -
    • allocate space for an address,
    • -
    • name it p,
    • -
    • record its type as “pointer to int”
    • -
    -
  • -
  • “p = ∧i;” -
      -
    • “&i” is the address of “i”
    • -
    • store ∧i in p
    • -
    • so, p becomes a pointer to i
    • -
    -
  • -
  • “cout « i;” -
      -
    • outputs the value stored in i, 5
    • -
    -
  • -
  • “cout « p;” -
      -
    • outputs the address of i: 0xbffffbbc
    • -
    -
  • -
  • “cout « *p;” -
      -
    • ”*” dereferences p. That is, *p is the value pointed to by p. In this case 5
    • -
    -
  • -
- -

Diagram of memory:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressNameValue
254i5
923p254
- -

Second diagram of memory:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressNameValueSize
0x6fffbei54 bytes
???p0x6fffbe4 bytesa
- -

Slide showing program code: see pointers.c

- -

Slide showing output: see output.txt

- -

Slide showing same program with different highlights.

- -

Slide showing same output with different highlights.

- -

End

- -
-
-
-
- - diff --git a/_site/melody/cmpt-225/03/output.txt b/_site/melody/cmpt-225/03/output.txt deleted file mode 100644 index fa087ce..0000000 --- a/_site/melody/cmpt-225/03/output.txt +++ /dev/null @@ -1,38 +0,0 @@ -main() begin -XXXX = 111111111 -XXXX is stored at &XXXX = 0xfffff40750e0 -YYYY is a pointer to XXXX: YYYY = 0xfffff40750e0 -* dereferences the pointer: *YYYY = 111111111 -Array AAAA can be accessed with array notaions: - AAAA[0] = 222222222 - AAAA[1] = 333333333 - AAAA[2] = 444444444 - -Array variable AAAA is a pointer to A[0]: AAAA = 0xfffff40750f8 -So, dereferencing AAAA should give us A[0]: *AAAA = 222222222 - -Adding 1 to an int pointer makes it point to the next int -AAAA = 0xfffff40750f8 -AAAA+1 = 0xfffff40750fc -*(AAAA+1) = 333333333 - -We can look at contents of a chunk of memory: -Peeking at the memory in the neighbourhood of &XXXX, we see: - -Address Contents in Hex Contents in Decimal -0xfffff40750fc: 13de4355 = 333333333 -0xfffff40750f8: d3ed78e = 222222222 -0xfffff40750f4: ffff = 65535 -0xfffff40750f0: f40750e0 = -200847136 -0xfffff40750ec: ffff = 65535 -0xfffff40750e8: f40750e8 = -200847128 -0xfffff40750e4: 6 = 6 -0xfffff40750e0: 69f6bc7 = 111111111 -0xfffff40750dc: ffff = 65535 -0xfffff40750d8: a478f4e0 = -1535576864 -0xfffff40750d4: aaaa = 43690 -0xfffff40750d0: c46a13e0 = -999681056 -0xfffff40750cc: ffff = 65535 -0xfffff40750c8: a478f538 = -1535576776 -0xfffff40750c4: ffff = 65535 -main() ends diff --git a/_site/melody/cmpt-225/03/pointers.cpp b/_site/melody/cmpt-225/03/pointers.cpp deleted file mode 100644 index 09940ec..0000000 --- a/_site/melody/cmpt-225/03/pointers.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* a small program to demonstrate C++ addresses, pointers and arrays */ - -#include /* Tait: missing name for import */ -#include /* Tait: missing name from import */ -using namespace std; - -int main(){ - cout << "main() begin\n"; - - int XXXX = 111111111; - cout << "XXXX = " << XXXX << endl; - cout << "XXXX is stored at &XXXX = " << &XXXX << endl; - - int * YYYY = &XXXX; - cout << "YYYY is a pointer to XXXX: YYYY = " << YYYY << endl; - cout << "* dereferences the pointer: *YYYY = " << *YYYY << endl; - - int AAAA[3] = { 222222222, 333333333, 444444444 }; - cout << "Array AAAA can be accessed with array notaions: " << endl; - cout << " AAAA[0] = " << AAAA[0] << endl; - cout << " AAAA[1] = " << AAAA[1] << endl; - cout << " AAAA[2] = " << AAAA[2] << endl << endl; - - cout << "Array variable AAAA is a pointer to A[0]: AAAA = " << AAAA << endl; - cout << "So, dereferencing AAAA should give us A[0]: *AAAA = " << *AAAA << endl << endl; - - cout << "Adding 1 to an int pointer makes it point to the next int" << endl; - cout << "AAAA = " << AAAA << endl; - cout << "AAAA+1 = " << (AAAA+1) << endl; - cout << "*(AAAA+1) = " << *(AAAA+1) << endl << endl; - - cout << "We can look at contents of a chunk of memory:" << endl; - cout << "Peeking at the memory in the neighbourhood of &XXXX, we see: " << endl << endl; - cout << "Address Contents in Hex Contents in Decimal " << endl; - int * p = (&XXXX)+7; - - for (int i = 0; i < 15; i++) { - cout << p << ": " << setw(8) << hex << *p << " = " << setw(11) << dec << *p << endl; - p -= 1; - } - - cout << "main() ends" << endl; -} diff --git a/_site/melody/cmpt-295/01/Lecture_01_Activity_Code.pdf b/_site/melody/cmpt-295/01/Lecture_01_Activity_Code.pdf deleted file mode 100644 index 5abb1e8..0000000 Binary files a/_site/melody/cmpt-295/01/Lecture_01_Activity_Code.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/01/Lecture_01_Activity_Code.pdf.txt b/_site/melody/cmpt-295/01/Lecture_01_Activity_Code.pdf.txt deleted file mode 100644 index ebb2c7d..0000000 --- a/_site/melody/cmpt-295/01/Lecture_01_Activity_Code.pdf.txt +++ /dev/null @@ -1,22 +0,0 @@ -Title: Activity - Code - -Video of CERT Secure Coding Initiative Conference 2015 - Robert C. Seacord - -https://www.youtube.com/watch?v=1ew0GvB3NpE - -Blue box with code in it: - -char *copy (size_t n, const char *a) { - if (n == 0) return NULL; - if (a == NULL) return NULL; - char *p = (char *)malloc(n); - - if (p == NULL) return NULL; - - for (int i = 0; i < n; i++) p[i] = *a++; - - return p; - -} - -White text over-laying the blue box: Spot the defect diff --git a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview.pdf b/_site/melody/cmpt-295/01/Lecture_01_Course_Overview.pdf deleted file mode 100644 index 2a28cfb..0000000 Binary files a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_Annotated.md b/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_Annotated.md deleted file mode 100644 index a7444e8..0000000 --- a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_Annotated.md +++ /dev/null @@ -1,105 +0,0 @@ - - -# Welcome to CMPT 295 -## Introduction to Computer Systems - -My name is Anne Lavergne - -Lecture 1 – Course Overview + Activity - - - -## Today’s Menu [1] - -* COVID Protocol -* What is CMPT 295? - * What shall we learn in CMPT 295? - * What should we already know? - * Which resources do we have to help us learn all this? -* Activity -* Questions - -## COVID protocol – About masks! [2] -Here is a message from Elizabeth Elle, SFU Vice Provost Learning & Teaching, based on the public health order: - -* Unless we have an approved exemption, we are required to wear a mask in all indoor common and learning spaces, including classrooms. Please come to campus prepared with a non-medical mask. - * If we forget our mask, disposable masks are available from Student Central in Burnaby and at the information desks in Vancouver and Surrey. - * If we require a mask exemption in the classroom for medical reasons, please contact the Centre for Accessible Learning at cal_admin@sfu.ca for assistance. - * If we are requesting mask exemptions on other protected grounds, such as religion, we can contact the Office of Student Support, Rights and Responsibilities at student_support@sfu.ca. -* And please remember to be kind to each other. If we see someone not wearing a mask, do not make assumptions or judgments as that person may be exempt. - -## What is CMPT 295? [3] - -* The goal of this course is to give us, software developers, a look “under the hood” of a computer, i.e., to learn about Computer Systems => microprocessor, memory, … a car with its hood up. -* This knowledge will allow us to become more efficient software developers - -## The big picture: [4] - -In CMPT 295, we shall learn … - -* C programs (.c) -- How our code and data are represented in memory -* Assembly programs (.s) -- How a compiler transforms our code into machine executable code in several steps -* Object (.o) file an executable -- How a compiler optimizes (or not) our code -* Computer executes it -- How a microprocessor is designed and how it executes our code -* CPU, Memory -- How memory is designed - -How all of this can impact the execution of our code How to write more efficient and reliable code: -* Be able to find and eliminate bugs -more efficiently -* Be able to ascertain program performance and tune it by optimizing our code - -## What should we already know? [5] - -* Write correct C programs - * C constructs (variables, data types, pointers, if/else, switch/case, for/while/do while, function calls, arrays, …) -* What a stack is and how it works -* Binary/decimal/hexadecimal numeral systems - * How to convert from one numeral system to the others - * Basic arithmetic -* Perform Boolean algebra using and, or, not, xor - -## Which resources do we have? [6] - -* Course web site -https://www2.cs.sfu.ca/CourseCentral/295/alavergn/index.html -* Textbook - * Computer Systems: A Programmer's Perspective, 3/E, Randal E. Bryant, David R. O'Hallaron, Pearson, 2016 -* Labs in CSIL (Computing Science Instructional Lab) - * Target Machine: CSIL workstation - * Linux platform (or OS) - * C programming language - * x86-64 assembly language - * gcc compiler -* Instructor and TAs - Office hours - -## Activity - Discover our resources [7] - -Instructions: -1. Form teams of 3 to 4 -2. Do Lecture 1 Activity on CourSys -3. Time: about 30 minutes - -## Question? [8] - -Blank page. - -## Summary [9] - -* COVID Protocol -* What is CMPT 295? - * What shall we learn in CMPT 295? - * What should we already know? - * Which resources do we have to help us learn all this? -* Activity -* Questions - -## Next Lecture [10] - -* Data Representation - * Representing information as bits - -* To get ready for our next lecture: - * Optional: Read Chapter 1 of textbook - * Not so optional: Read Section 2.1 of Chapter 2 - * Download the partial lecture notes found under the column Lecture in the table on our course web site - diff --git a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_Annotated.pdf b/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_Annotated.pdf deleted file mode 100644 index 13a0bf7..0000000 Binary files a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_Annotated.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_annotated.html b/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_annotated.html deleted file mode 100644 index a747f24..0000000 --- a/_site/melody/cmpt-295/01/Lecture_01_Course_Overview_annotated.html +++ /dev/null @@ -1,170 +0,0 @@ -

- -

Welcome to CMPT 295

- -

Introduction to Computer Systems

- -

My name is Anne Lavergne

- -

Lecture 1 – Course Overview + Activity

- -

- -

Today’s Menu [1]

- -
    -
  • COVID Protocol
  • -
  • What is CMPT 295? - -
      -
    • What shall we learn in CMPT 295?
    • -
    • What should we already know?
    • -
    • Which resources do we have to help us learn all this?
    • -
    -
  • -
  • Activity
  • -
  • Questions
  • -
- - -

COVID protocol – About masks! [2]

- -

Here is a message from Elizabeth Elle, SFU Vice Provost Learning & Teaching, based on the public health order:

- -
    -
  • Unless we have an approved exemption, we are required to wear a mask in all indoor common and learning spaces, including classrooms. Please come to campus prepared with a non-medical mask. - -
      -
    • If we forget our mask, disposable masks are available from Student Central in Burnaby and at the information desks in Vancouver and Surrey.
    • -
    • If we require a mask exemption in the classroom for medical reasons, please contact the Centre for Accessible Learning at cal_admin@sfu.ca for assistance.
    • -
    • If we are requesting mask exemptions on other protected grounds, such as religion, we can contact the Office of Student Support, Rights and Responsibilities at student_support@sfu.ca.
    • -
    -
  • -
  • And please remember to be kind to each other. If we see someone not wearing a mask, do not make assumptions or judgments as that person may be exempt.
  • -
- - -

What is CMPT 295? [3]

- -
    -
  • The goal of this course is to give us, software developers, a look “under the hood” of a computer, i.e., to learn about Computer Systems => microprocessor, memory, … a car with its hood up.
  • -
  • This knowledge will allow us to become more efficient software developers
  • -
- - -

The big picture: [4]

- -

In CMPT 295, we shall learn …

- -

C programs (.c) – How our code and data are represented in memory

- -

Assembly programs (.s) – How a compiler transforms our code into machine executable code in several steps

- -

Object (.o) file an executable – How a compiler optimizes (or not) our code

- -

Computer executes it – How a microprocessor is designed and how it executes our code

- -

CPU, Memory – How memory is designed

- -

How all of this can impact the execution of our code How to write more efficient and reliable code: -* Be able to find and eliminate bugs -more efficiently -* Be able to ascertain program performance and tune it by optimizing our code

- -

What should we already know? [5]

- -
    -
  • Write correct C programs - -
      -
    • C constructs (variables, data types, pointers, if/else, switch/case, for/while/do while, function calls, arrays, …)
    • -
    -
  • -
  • What a stack is and how it works
  • -
  • Binary/decimal/hexadecimal numeral systems - -
      -
    • How to convert from one numeral system to the others
    • -
    • Basic arithmetic
    • -
    -
  • -
  • Perform Boolean algebra using and, or, not, xor
  • -
- - -

Which resources do we have? [6]

- -
    -
  • Course web site -https://www2.cs.sfu.ca/CourseCentral/295/alavergn/index.html
  • -
  • Textbook - -
      -
    • Computer Systems: A Programmer’s Perspective, 3/E, Randal E. Bryant, David R. O'Hallaron, Pearson, 2016
    • -
    -
  • -
  • Labs in CSIL (Computing Science Instructional Lab) - -
      -
    • Target Machine: CSIL workstation - -
        -
      • Linux platform (or OS)
      • -
      • C programming language
      • -
      • x86-64 assembly language
      • -
      • gcc compiler
      • -
      -
    • -
    -
  • -
  • Instructor and TAs - Office hours
  • -
- - -

Activity - Discover our resources [7]

- -

Instructions: -1. Form teams of 3 to 4 -2. Do Lecture 1 Activity on CourSys -3. Time: about 30 minutes

- -

Question? [8]

- -

Blank page.

- -

Summary [9]

- -
    -
  • COVID Protocol
  • -
  • What is CMPT 295? - -
      -
    • What shall we learn in CMPT 295?
    • -
    • What should we already know?
    • -
    • Which resources do we have to help us learn all this?
    • -
    -
  • -
  • Activity
  • -
  • Questions
  • -
- - -

Next Lecture [10]

- -
    -
  • Data Representation

    - -
      -
    • Representing information as bits
    • -
    -
  • -
  • To get ready for our next lecture:

    - -
      -
    • Optional: Read Chapter 1 of textbook
    • -
    • Not so optional: Read Section 2.1 of Chapter 2
    • -
    • Download the partial lecture notes found under the column Lecture in the table on our course web site
    • -
    -
  • -
- diff --git a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro.pdf b/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro.pdf deleted file mode 100644 index 03015a0..0000000 Binary files a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.html b/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.html deleted file mode 100644 index af38496..0000000 --- a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.html +++ /dev/null @@ -1,1214 +0,0 @@ - - - - - | tait.tech - - - - -
-
-

CMPT 295

- -

Unit: Textbook Chapter 2 - Data Representation

- -

Lecture 2 - Representing data in memory

- -

Data = information = data, instructions (code, programs)

- -

CAL Volunteer Note-Taker Position [1]

- -
    -
  • If you are taking lecture notes in CMPT 295 and your hand writing is you may be interested in applying for the following volunteer note-taker position: -
      -
    • The Centre for Accessible Learning (CAL) is looking for a CMPT 295 notetaker
    • -
    • CAL volunteer lecture note-takers are provided with a $100 credit applied to their student account in acknowledgment of their assistance
    • -
    -
  • -
  • Interested?
  • -
  • Please see the email CAL has sent us
  • -
  • Please feel free to call 778-782-3112 or email calexams@sfu.ca the Centre if -you have any questions
  • -
- -

Last Lecture [2]

-
    -
  • COVID Protocol
  • -
  • What is CMPT 295? -
      -
    • What shall we learn in CMPT 295?
    • -
    • What should we already know?
    • -
    • Which resources do we have to help us learn all this?
    • -
    -
  • -
  • Activity
  • -
  • Questions
  • -
- -

Feedback on Lecture 1 Activity [3]

-
    -
  • Thank you for participating in the Lecture 1 Activity!
  • -
  • Feedback now posted on our course web site
  • -
  • Check it out!
  • -
- -

Unit Objectives [4]

- -

Chapter 2 of our textbook

- -
    -
  • Understand how a computer represents (encodes) data in (fixed-size) memory
  • -
  • Become aware of the impact this fixed size has on … -
      -
    • Range of values represented in memory
    • -
    • Results of arithmetic operations
    • -
    -
  • -
  • Become aware of … -
      -
    • How one data type is converted to another
    • -
    • And the impact this conversion has on the values
    • -
    -
  • -
  • Bottom Line: allow software developers to write more reliable code
  • -
- -

Today’s Menu [5]

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -6 -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -

“Under the hood” Von Neumann architecture [6]

- -

Architecture of most computers

- -

Its features:

-
    -
  • CPU, memory, -input and ouput, bus
  • -
  • -

    (circled in red) Data and instructions -(code/programs) both stored in memory

    -
  • -
  • C programs (.c) – How our code and data are represented in memory
  • -
  • Assembly programs (.s) – How a compiler transforms our code into machine executable code in several steps
  • -
  • Object (.o) file an executable – How a compiler optimizes (or not) our code
  • -
  • Computer executes it – How a microprocessor is designed and how it executes our code
  • -
  • CPU, Memory – How memory is designed
  • -
- -

“Computer executes it” has a diagram attached.

- -

Two I/O devices are shown (represented by a cylindar), one on the left, one one the right. -On the left is “input peripheral”, on the right is “output peripheral”.

- -

A red box surrounds the two central nodes (represented by squares), labeled “motherboard”. -It contains two items inside it. -On the left is the “Central Processing Unit (CPU)”, which executes instructions. -On the right is “Memory”, which is “volatile” and stores data and instructions.

- -

An arrow points from the far left input peripheral to the CPU. -A bi-directional arrow points between the CPU and memory. -A final arrow points from memory to the output peripheral.

- -

How to diagram memory [7]

-
    -
  • Seen as a linear (contiguous) array of bytes
  • -
  • 1 byte (8 bits) smallest addressable unit of memory -
      -
    • Each byte has a unique address
    • -
    • Byte-addressable memory
    • -
    -
  • -
  • Computer reads a word worth of bits at a time (=> word size)
  • -
  • Questions: -
      -
    1. If word size is 8, how many bytes are read at a time from memory? -Answer: (annotated) 1 byte
    2. -
    3. If a computer can read 4 bytes at a time, its -word size is (annotated) 32 bits.
    4. -
    -
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0008 
0x0007 
0x0006 
0x0005 
0x0004 
0x0003 
0x0002 
0x0001 
0x00001 byte
- -

Closer look at memory [8]

- -

Typically, in a diagram, we represent memory (memory content) as a series of memory “cells” (or bits) in which one of two possible values (‘0’ and ‘1’) is stored

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0008 
0x0007 
0x0006 
0x0005 
0x0004 
0x0003 
0x0002 
0x0001 
0x000001000000
- -

0x0000 is labled as “1 memory cell”

- -

Compressed view of memory [9]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0008 
0x00077
0x00066
0x00055
0x00044
0x00033
0x00022
0x00011
0x00000
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]       
size−8        
        
0x0018        
0x0010 (annotation: why is this not `0x0016)        
0x0008        
0x000001234567
- -

Each cell, no matter which diagram is used, represents 1 byte, or 8 bits. -0x0000 to 0x0008 is eight bytes, or 64 bits.

- -

Why can only two possible values be stored in a memory “cell”?

- -
    -
  • As electronic machines, computers use two voltage levels -
      -
    • Transmitted on noisy wires -> value of two voltage levels vary over a range
    • -
    • These ranges are abstracted using “0” and “1”
    • -
    -
  • -
- -

A diagram shows two horizontal green bars. -Bar one has a minimum of 0.0V, and a maximum of 0.2V. “0” -Bar two has a minimum of 0.9V, and a maximum of 1.1V. “1” -A wiggly line jiggles around somewhat randomly within the confines of the lower “0” bar–moving to the right with time, it moves up, temporarily traversing the whitespace between the two bars before settling back down in its jiggly pattern within the “1” bar. -It then reverses this step, through the whitespace back to the “0” bar where it started.

- -
    -
  • Back to the question Why can only two possible values be stored in a -memory “cell”? -
      -
    • Because computers manipulate two-valued information
    • -
    -
  • -
- -

A bit of history [11]

- -

ENIAC: Electronic Numerical Integrator And Calculator

-
    -
  • U. Penn by Eckert + Mauchly (1946)
  • -
  • Data: 20 × 10-digit regs + ~18,000 vacuum tubes
  • -
  • To code: manually set switches and plugged cables -
      -
    • Debugging was manual
    • -
    • No method to save program for later use
    • -
    • Separated code from the data
    • -
    -
  • -
- -

Source: https://en.wikipedia.org/wiki/ENIAC#/media/File:ENIAC_Penn1.jpg

- -

Review [12] – Back to our bits – How to represent series of bits

-
    -
  • From binary numeral system
  • -
  • Base: 2
  • -
  • Bit values: 0 and 1
  • -
  • Possible bit patterns in a byte: 000000002 to 111111112
  • -
  • Drawback of manipulating binary numbers? -
      -
    • What number is this? -
        -
      • 1001100 11001001 01000101 010010002
      • -
      -
    • -
    • Lengthy to write -> not very compact
    • -
    • Difficult to read
    • -
    -
  • -
- -

Annotation: “Error prone!” encompasses “lengthy to write” and “difficult to read”.

- -

Review – A solution: hexadecimal numbers

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DecimalBinaryHexidecimal
000000
100011
200102
30011 (circled in annotation)3
401004
50101 (circled in annotation)5
601106
701117
810008
910019
101010A
111011B
121100C
131101 (circled in annotation)D
141110E
151111 (circled in annotation)F
- -
    -
  • Base: 16
  • -
  • Values: 0, 1, 2, …, 9, A, B, C, D, E, F
  • -
  • Possible patterns in a byte: 0016 to FF16
  • -
  • Conversion binary -> hex (hex is in annotation, binary numbers grouped by 4 by green lines) -
      -
    • e.g.: 0100(0x4) 1100(0xC) 1100(0xC) 1001(0x9) 0100(0x4) 0101(0x5) 0100(0x4) 1000(0xB)
    • -
    • annotation: conversion algorithm?
    • -
    -
  • -
  • Conversion hex -> binary (binary in annotation, an arrow points off from each hex character to the binary sequence representing it) -
      -
    • e.g.: 3(0011) D(1101) 5(0101) F(1111) (in C: 0x3D5F)
    • -
    • annotation: conversion algorithm?
    • -
    -
  • -
- -

What could these 32 bits represent? – What kind of information could they encode?

- -

011000100110100101110100011100112

- -

Answer:

-
    -
  • Integer
  • -
  • string of cleartexts
  • -
  • colour
  • -
- -

What kind of information (data) do series of bits represent?

- -

Encoding Scheme

- -

Bit pattern: -01100010 01101001 -01110100 011100112

- -

An arrow pointing to a box labeled “encoding schemes”:

- -
    -
  • ASCII character
  • -
  • Unsigned integer
  • -
  • Two’s complement (signed) integer
  • -
  • Floating point
  • -
  • Memory Address
  • -
  • Assembly language
  • -
  • RGB
  • -
  • MP3
  • -
  • -
- -

An arrow pointing to the following list:

- -
    -
  • Letters and symbols
  • -
  • Positive numbers
  • -
  • Negative numbers
  • -
  • Real numbers
  • -
  • C pointers
  • -
  • Machine-level instructions
  • -
  • Colour
  • -
  • Audio/Sound
  • -
  • -
- -

Definition: An encoding scheme is an interpretation (representation) of a series of bits

- -

Bottom line: Which encoding scheme is used to interpret a series of bits depends on the application currently executing (the “context”) not the computer

- -

Endian – Order of bytes in memory

-
    -
  • It is straight forward to store a byte in memory -
      -
    • All we need is the byte (series of bits) and a memory address
    • -
    • For example, let’s store byte 011100112 at address 0x0000
    • -
    -
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0003 
0x0002 
0x0001 
0x0000011100112
- -

Endian – Order of bytes in memory

- -

Question: But how do we store several bytes in memory?

-
    -
  • For example, let’s store these 4 bytes starting at address 0x0000
  • -
- -

01000010 01101001 01110100 011100112

- - - -

Way 1: Little endian -Address|M[]|Hex (filled out as annotation) -size-1|| -…|| -0x0003|01000010|42 -0x0002|01101001|69 -0x0001|01110100|74 -0x0000|01110011|73

- -

Way 2: Big endian

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]Hex
size−1  
  
0x00030111001173
0x00020111010074
0x00010110100169
0x00000100001042
- -

Compressed view of memory:

- -

Little-endian:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Address       
size-8       
       
0x0008       
0x000073746942   
- -

Big-endian:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Address       
       
0x0008       
0x000042697473   
- -

Review Bit – Bit Manipulation - Boolean algebra

- -

No matter what a series of bits represent, they can be manipulated using bit-level operations:

-
    -
  • Boolean algebra
  • -
  • -

    Shifting

    -
  • -
  • Developed by George Boole in 19th Century -
      -
    • Algebraic representation of logic -
        -
      • Encode “True” as 1 and “False” as 0
      • -
      -
    • -
    -
  • -
- -

AND -> A&B = 1 when both A=1 and B=1

- - - - - - - - - - - - - - - - - - - -
&01
000
101
- -

NOT -> ~A = 1 when A=0

- - - - - - - - - - - - - - - - -
~ 
01
10
- - - - - - - - -
OR -> AB = 1 when either A=1 or B=1
- - - - - - - - - - - - - - - - - - - -
|01
001
111
- -

XOR (Exclusive-Or) -> A^B = 1 when either A=1 or B=1, but not both

- - - - - - - - - - - - - - - - - - - -
^01
001
110
- -

Interesting fact about Boolean algebra and digital logic

- -
    -
  • Claude Shannon – 1937 master’s thesis
  • -
  • Made connection between Boolean algebra and digital logic -
      -
    • Boolean algebra could be applied to design and analysis of digital -systems (digital circuits)
    • -
    -
  • -
  • Example:
  • -
- -

Diagram of an AND gate.

- -

Two lines go into a black box. -One is 1/high, one is 0/low. -An output comes out the other side: 0/low.

- -

Review (annotation: HW2)

- -

Let’s try some Boolean algebra!

- -
    -
  • Operations applied bitwise -> to each bit
  • -
  • Spot the error(s):
  • -
- -
-  01101001
-& 01010101
-= 01000001
-
- -
-  01101001
-| 01010101
-= 01111101
-
- -
-  01101001
-^ 01010101
-= 00111100
-
-(notation on 2nd last bit of equals: error!)
-
- -
-~ 01010101
-= 10101010
-
- -

Useful bit manipulations

-
    -
  • Using a binary mask (or bit mask) as an operand -
      -
    1. AND: Extracts particular bit(s) so we can test whether they are set. Example:
    2. -
    -
  • -
-
-  10110011 <- some value x
-& 00000001 <- binary mask
-  00000001
-
-

The result tells us that the least significant bit (LSb) is set.

-
    -
  1. XOR: Toggle specific bits - Example: The result tells us that the least significant bit (LSb) of x is set
  2. -
-
-  10110011 <- some value x
-^ 00011100 <- binary mask
-= 10101111 We get a toggled version of the 3 original bits (of x) that
-
-

(red square around bits 4-6): “We get a toggled version of the three original bits (of x) that corresponds to the 3 set bits of the binary mask.”

-
    -
  • Using two operands -
      -
    1. OR: Merge all set bits of operands -
        -
      • Example:
      • -
      -
    2. -
    -
  • -
-
-  10110011 <- some value x
-| 00011100 <- some value y
-= 10111111
-
-

The result contains all the set bits of x and y.

- -

Bit Manipulation - Shift operations

- -
    -
  • LSb: least significant bit is the rightmost bit of a series of bits (or bit vector)
  • -
  • -

    MSb: most significant bit is the leftmost bit of a series of bits (or bit vector)

    -
  • -
  • Left Shift: x « y -
      -
    • Shift bit vector (a series of bits) x left y positions. -
        -
      • Effect: -
          -
        • Throw away y most significant bits (MSb) of x on left
        • -
        • Fill x with y 0’s on right
        • -
        -
      • -
      -
    • -
    -
  • -
  • Right Shift: x » y -
      -
    • Shift bit vector x right y positions
    • -
    • Effect: -
        -
      • Throw away y least significant bits (LSb) of x on right
      • -
      -
    • -
    • Logical shift: Fill x with y 0’s on left
    • -
    • Arithmetic shift: Fill x with y copies of x‘s sign bit on left
    • -
    • Sign bit: most significant bit (MSb) of x (before shifting occurred)
    • -
    -
  • -
- -

Bit Manipulation - Shift operations – Let’s try! (HW3)

- -
    -
  • Left Shift: 10111001 « 4 = 10010000
  • -
  • -

    Left Shift: 10111001 « 2 = 11100100

    -
  • -
  • Right Shift (logical): 00111001 » 4 = 00000011
  • -
  • Right Shift (arithmatic): 10111001 » 4 = 11111011
  • -
  • Right Shift (logical/arithmatic): 10111001 » 2 = 00101110/11101110
  • -
- -

Summary

- -
    -
  • Von Neumann architecture -
      -
    • Architecture of most computers
    • -
    • Its components: CPU, memory, input and ouput, bus
    • -
    • One of its characteristics: Data and code (programs) both stored in memory
    • -
    -
  • -
  • A look at memory: defined byte-addressable memory, diagram of (compressed) memory -
      -
    • Word size (w): size of a series of bits (or bit vector) we manipulate, also size of machine words (see Section 2.1.2)
    • -
    -
  • -
  • A look at bits in memory -
      -
    • Why binary numeral system (0 and 1 -> two values) is used to represent information in memory
    • -
    • Algorithm for converting binary to hexadecimal (hex) -
        -
      1. Partition bit vector into groups of 4 bits, starting from right, i.e., least significant byte (LSB) -
          -
        • If most significant “byte” (MSB) does not have 8 bits, pad it: add 0’s to its left
        • -
        -
      2. -
      3. Translate each group of 4 bits into its hex value
      4. -
      -
    • -
    • What do bits represent? Encoding scheme gives meaning to bits
    • -
    • Order of bytes in memory: little endian versus big endian
    • -
    -
  • -
  • Bit manipulation – regardless of what bit vectors represent -
      -
    • - - - - - - - -
      Boolean algebra: bitwise operations => AND (&), OR (), XOR (^), NOT (~)
      -
    • -
    • Shift operations: left shift, right logical shift and right arithmetic shift -
        -
      • Logical shift: Fill x with y 0’s on left
      • -
      • Arithmetic shift: Fill x with y copies of x‘s sign bit on left
      • -
      • Sign bit: Most significant bit (MSb) before shifting occurred
      • -
      -
    • -
    -
  • -
- - - - - - - - - - -
NOTE: C logical operators and C bitwise (bit-level) operators behave differently! Watch out for && versus &, versus, …
- -

Next Lecture

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -
-
-
-
- - diff --git a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.pdf b/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.pdf deleted file mode 100644 index b6a0d56..0000000 Binary files a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated/index.html b/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated/index.html deleted file mode 100644 index af38496..0000000 --- a/_site/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated/index.html +++ /dev/null @@ -1,1214 +0,0 @@ - - - - - | tait.tech - - - - -
-
-

CMPT 295

- -

Unit: Textbook Chapter 2 - Data Representation

- -

Lecture 2 - Representing data in memory

- -

Data = information = data, instructions (code, programs)

- -

CAL Volunteer Note-Taker Position [1]

- -
    -
  • If you are taking lecture notes in CMPT 295 and your hand writing is you may be interested in applying for the following volunteer note-taker position: -
      -
    • The Centre for Accessible Learning (CAL) is looking for a CMPT 295 notetaker
    • -
    • CAL volunteer lecture note-takers are provided with a $100 credit applied to their student account in acknowledgment of their assistance
    • -
    -
  • -
  • Interested?
  • -
  • Please see the email CAL has sent us
  • -
  • Please feel free to call 778-782-3112 or email calexams@sfu.ca the Centre if -you have any questions
  • -
- -

Last Lecture [2]

-
    -
  • COVID Protocol
  • -
  • What is CMPT 295? -
      -
    • What shall we learn in CMPT 295?
    • -
    • What should we already know?
    • -
    • Which resources do we have to help us learn all this?
    • -
    -
  • -
  • Activity
  • -
  • Questions
  • -
- -

Feedback on Lecture 1 Activity [3]

-
    -
  • Thank you for participating in the Lecture 1 Activity!
  • -
  • Feedback now posted on our course web site
  • -
  • Check it out!
  • -
- -

Unit Objectives [4]

- -

Chapter 2 of our textbook

- -
    -
  • Understand how a computer represents (encodes) data in (fixed-size) memory
  • -
  • Become aware of the impact this fixed size has on … -
      -
    • Range of values represented in memory
    • -
    • Results of arithmetic operations
    • -
    -
  • -
  • Become aware of … -
      -
    • How one data type is converted to another
    • -
    • And the impact this conversion has on the values
    • -
    -
  • -
  • Bottom Line: allow software developers to write more reliable code
  • -
- -

Today’s Menu [5]

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -6 -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -

“Under the hood” Von Neumann architecture [6]

- -

Architecture of most computers

- -

Its features:

-
    -
  • CPU, memory, -input and ouput, bus
  • -
  • -

    (circled in red) Data and instructions -(code/programs) both stored in memory

    -
  • -
  • C programs (.c) – How our code and data are represented in memory
  • -
  • Assembly programs (.s) – How a compiler transforms our code into machine executable code in several steps
  • -
  • Object (.o) file an executable – How a compiler optimizes (or not) our code
  • -
  • Computer executes it – How a microprocessor is designed and how it executes our code
  • -
  • CPU, Memory – How memory is designed
  • -
- -

“Computer executes it” has a diagram attached.

- -

Two I/O devices are shown (represented by a cylindar), one on the left, one one the right. -On the left is “input peripheral”, on the right is “output peripheral”.

- -

A red box surrounds the two central nodes (represented by squares), labeled “motherboard”. -It contains two items inside it. -On the left is the “Central Processing Unit (CPU)”, which executes instructions. -On the right is “Memory”, which is “volatile” and stores data and instructions.

- -

An arrow points from the far left input peripheral to the CPU. -A bi-directional arrow points between the CPU and memory. -A final arrow points from memory to the output peripheral.

- -

How to diagram memory [7]

-
    -
  • Seen as a linear (contiguous) array of bytes
  • -
  • 1 byte (8 bits) smallest addressable unit of memory -
      -
    • Each byte has a unique address
    • -
    • Byte-addressable memory
    • -
    -
  • -
  • Computer reads a word worth of bits at a time (=> word size)
  • -
  • Questions: -
      -
    1. If word size is 8, how many bytes are read at a time from memory? -Answer: (annotated) 1 byte
    2. -
    3. If a computer can read 4 bytes at a time, its -word size is (annotated) 32 bits.
    4. -
    -
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0008 
0x0007 
0x0006 
0x0005 
0x0004 
0x0003 
0x0002 
0x0001 
0x00001 byte
- -

Closer look at memory [8]

- -

Typically, in a diagram, we represent memory (memory content) as a series of memory “cells” (or bits) in which one of two possible values (‘0’ and ‘1’) is stored

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0008 
0x0007 
0x0006 
0x0005 
0x0004 
0x0003 
0x0002 
0x0001 
0x000001000000
- -

0x0000 is labled as “1 memory cell”

- -

Compressed view of memory [9]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0008 
0x00077
0x00066
0x00055
0x00044
0x00033
0x00022
0x00011
0x00000
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]       
size−8        
        
0x0018        
0x0010 (annotation: why is this not `0x0016)        
0x0008        
0x000001234567
- -

Each cell, no matter which diagram is used, represents 1 byte, or 8 bits. -0x0000 to 0x0008 is eight bytes, or 64 bits.

- -

Why can only two possible values be stored in a memory “cell”?

- -
    -
  • As electronic machines, computers use two voltage levels -
      -
    • Transmitted on noisy wires -> value of two voltage levels vary over a range
    • -
    • These ranges are abstracted using “0” and “1”
    • -
    -
  • -
- -

A diagram shows two horizontal green bars. -Bar one has a minimum of 0.0V, and a maximum of 0.2V. “0” -Bar two has a minimum of 0.9V, and a maximum of 1.1V. “1” -A wiggly line jiggles around somewhat randomly within the confines of the lower “0” bar–moving to the right with time, it moves up, temporarily traversing the whitespace between the two bars before settling back down in its jiggly pattern within the “1” bar. -It then reverses this step, through the whitespace back to the “0” bar where it started.

- -
    -
  • Back to the question Why can only two possible values be stored in a -memory “cell”? -
      -
    • Because computers manipulate two-valued information
    • -
    -
  • -
- -

A bit of history [11]

- -

ENIAC: Electronic Numerical Integrator And Calculator

-
    -
  • U. Penn by Eckert + Mauchly (1946)
  • -
  • Data: 20 × 10-digit regs + ~18,000 vacuum tubes
  • -
  • To code: manually set switches and plugged cables -
      -
    • Debugging was manual
    • -
    • No method to save program for later use
    • -
    • Separated code from the data
    • -
    -
  • -
- -

Source: https://en.wikipedia.org/wiki/ENIAC#/media/File:ENIAC_Penn1.jpg

- -

Review [12] – Back to our bits – How to represent series of bits

-
    -
  • From binary numeral system
  • -
  • Base: 2
  • -
  • Bit values: 0 and 1
  • -
  • Possible bit patterns in a byte: 000000002 to 111111112
  • -
  • Drawback of manipulating binary numbers? -
      -
    • What number is this? -
        -
      • 1001100 11001001 01000101 010010002
      • -
      -
    • -
    • Lengthy to write -> not very compact
    • -
    • Difficult to read
    • -
    -
  • -
- -

Annotation: “Error prone!” encompasses “lengthy to write” and “difficult to read”.

- -

Review – A solution: hexadecimal numbers

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DecimalBinaryHexidecimal
000000
100011
200102
30011 (circled in annotation)3
401004
50101 (circled in annotation)5
601106
701117
810008
910019
101010A
111011B
121100C
131101 (circled in annotation)D
141110E
151111 (circled in annotation)F
- -
    -
  • Base: 16
  • -
  • Values: 0, 1, 2, …, 9, A, B, C, D, E, F
  • -
  • Possible patterns in a byte: 0016 to FF16
  • -
  • Conversion binary -> hex (hex is in annotation, binary numbers grouped by 4 by green lines) -
      -
    • e.g.: 0100(0x4) 1100(0xC) 1100(0xC) 1001(0x9) 0100(0x4) 0101(0x5) 0100(0x4) 1000(0xB)
    • -
    • annotation: conversion algorithm?
    • -
    -
  • -
  • Conversion hex -> binary (binary in annotation, an arrow points off from each hex character to the binary sequence representing it) -
      -
    • e.g.: 3(0011) D(1101) 5(0101) F(1111) (in C: 0x3D5F)
    • -
    • annotation: conversion algorithm?
    • -
    -
  • -
- -

What could these 32 bits represent? – What kind of information could they encode?

- -

011000100110100101110100011100112

- -

Answer:

-
    -
  • Integer
  • -
  • string of cleartexts
  • -
  • colour
  • -
- -

What kind of information (data) do series of bits represent?

- -

Encoding Scheme

- -

Bit pattern: -01100010 01101001 -01110100 011100112

- -

An arrow pointing to a box labeled “encoding schemes”:

- -
    -
  • ASCII character
  • -
  • Unsigned integer
  • -
  • Two’s complement (signed) integer
  • -
  • Floating point
  • -
  • Memory Address
  • -
  • Assembly language
  • -
  • RGB
  • -
  • MP3
  • -
  • -
- -

An arrow pointing to the following list:

- -
    -
  • Letters and symbols
  • -
  • Positive numbers
  • -
  • Negative numbers
  • -
  • Real numbers
  • -
  • C pointers
  • -
  • Machine-level instructions
  • -
  • Colour
  • -
  • Audio/Sound
  • -
  • -
- -

Definition: An encoding scheme is an interpretation (representation) of a series of bits

- -

Bottom line: Which encoding scheme is used to interpret a series of bits depends on the application currently executing (the “context”) not the computer

- -

Endian – Order of bytes in memory

-
    -
  • It is straight forward to store a byte in memory -
      -
    • All we need is the byte (series of bits) and a memory address
    • -
    • For example, let’s store byte 011100112 at address 0x0000
    • -
    -
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size−1 
 
0x0003 
0x0002 
0x0001 
0x0000011100112
- -

Endian – Order of bytes in memory

- -

Question: But how do we store several bytes in memory?

-
    -
  • For example, let’s store these 4 bytes starting at address 0x0000
  • -
- -

01000010 01101001 01110100 011100112

- - - -

Way 1: Little endian -Address|M[]|Hex (filled out as annotation) -size-1|| -…|| -0x0003|01000010|42 -0x0002|01101001|69 -0x0001|01110100|74 -0x0000|01110011|73

- -

Way 2: Big endian

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]Hex
size−1  
  
0x00030111001173
0x00020111010074
0x00010110100169
0x00000100001042
- -

Compressed view of memory:

- -

Little-endian:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Address       
size-8       
       
0x0008       
0x000073746942   
- -

Big-endian:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Address       
       
0x0008       
0x000042697473   
- -

Review Bit – Bit Manipulation - Boolean algebra

- -

No matter what a series of bits represent, they can be manipulated using bit-level operations:

-
    -
  • Boolean algebra
  • -
  • -

    Shifting

    -
  • -
  • Developed by George Boole in 19th Century -
      -
    • Algebraic representation of logic -
        -
      • Encode “True” as 1 and “False” as 0
      • -
      -
    • -
    -
  • -
- -

AND -> A&B = 1 when both A=1 and B=1

- - - - - - - - - - - - - - - - - - - -
&01
000
101
- -

NOT -> ~A = 1 when A=0

- - - - - - - - - - - - - - - - -
~ 
01
10
- - - - - - - - -
OR -> AB = 1 when either A=1 or B=1
- - - - - - - - - - - - - - - - - - - -
|01
001
111
- -

XOR (Exclusive-Or) -> A^B = 1 when either A=1 or B=1, but not both

- - - - - - - - - - - - - - - - - - - -
^01
001
110
- -

Interesting fact about Boolean algebra and digital logic

- -
    -
  • Claude Shannon – 1937 master’s thesis
  • -
  • Made connection between Boolean algebra and digital logic -
      -
    • Boolean algebra could be applied to design and analysis of digital -systems (digital circuits)
    • -
    -
  • -
  • Example:
  • -
- -

Diagram of an AND gate.

- -

Two lines go into a black box. -One is 1/high, one is 0/low. -An output comes out the other side: 0/low.

- -

Review (annotation: HW2)

- -

Let’s try some Boolean algebra!

- -
    -
  • Operations applied bitwise -> to each bit
  • -
  • Spot the error(s):
  • -
- -
-  01101001
-& 01010101
-= 01000001
-
- -
-  01101001
-| 01010101
-= 01111101
-
- -
-  01101001
-^ 01010101
-= 00111100
-
-(notation on 2nd last bit of equals: error!)
-
- -
-~ 01010101
-= 10101010
-
- -

Useful bit manipulations

-
    -
  • Using a binary mask (or bit mask) as an operand -
      -
    1. AND: Extracts particular bit(s) so we can test whether they are set. Example:
    2. -
    -
  • -
-
-  10110011 <- some value x
-& 00000001 <- binary mask
-  00000001
-
-

The result tells us that the least significant bit (LSb) is set.

-
    -
  1. XOR: Toggle specific bits - Example: The result tells us that the least significant bit (LSb) of x is set
  2. -
-
-  10110011 <- some value x
-^ 00011100 <- binary mask
-= 10101111 We get a toggled version of the 3 original bits (of x) that
-
-

(red square around bits 4-6): “We get a toggled version of the three original bits (of x) that corresponds to the 3 set bits of the binary mask.”

-
    -
  • Using two operands -
      -
    1. OR: Merge all set bits of operands -
        -
      • Example:
      • -
      -
    2. -
    -
  • -
-
-  10110011 <- some value x
-| 00011100 <- some value y
-= 10111111
-
-

The result contains all the set bits of x and y.

- -

Bit Manipulation - Shift operations

- -
    -
  • LSb: least significant bit is the rightmost bit of a series of bits (or bit vector)
  • -
  • -

    MSb: most significant bit is the leftmost bit of a series of bits (or bit vector)

    -
  • -
  • Left Shift: x « y -
      -
    • Shift bit vector (a series of bits) x left y positions. -
        -
      • Effect: -
          -
        • Throw away y most significant bits (MSb) of x on left
        • -
        • Fill x with y 0’s on right
        • -
        -
      • -
      -
    • -
    -
  • -
  • Right Shift: x » y -
      -
    • Shift bit vector x right y positions
    • -
    • Effect: -
        -
      • Throw away y least significant bits (LSb) of x on right
      • -
      -
    • -
    • Logical shift: Fill x with y 0’s on left
    • -
    • Arithmetic shift: Fill x with y copies of x‘s sign bit on left
    • -
    • Sign bit: most significant bit (MSb) of x (before shifting occurred)
    • -
    -
  • -
- -

Bit Manipulation - Shift operations – Let’s try! (HW3)

- -
    -
  • Left Shift: 10111001 « 4 = 10010000
  • -
  • -

    Left Shift: 10111001 « 2 = 11100100

    -
  • -
  • Right Shift (logical): 00111001 » 4 = 00000011
  • -
  • Right Shift (arithmatic): 10111001 » 4 = 11111011
  • -
  • Right Shift (logical/arithmatic): 10111001 » 2 = 00101110/11101110
  • -
- -

Summary

- -
    -
  • Von Neumann architecture -
      -
    • Architecture of most computers
    • -
    • Its components: CPU, memory, input and ouput, bus
    • -
    • One of its characteristics: Data and code (programs) both stored in memory
    • -
    -
  • -
  • A look at memory: defined byte-addressable memory, diagram of (compressed) memory -
      -
    • Word size (w): size of a series of bits (or bit vector) we manipulate, also size of machine words (see Section 2.1.2)
    • -
    -
  • -
  • A look at bits in memory -
      -
    • Why binary numeral system (0 and 1 -> two values) is used to represent information in memory
    • -
    • Algorithm for converting binary to hexadecimal (hex) -
        -
      1. Partition bit vector into groups of 4 bits, starting from right, i.e., least significant byte (LSB) -
          -
        • If most significant “byte” (MSB) does not have 8 bits, pad it: add 0’s to its left
        • -
        -
      2. -
      3. Translate each group of 4 bits into its hex value
      4. -
      -
    • -
    • What do bits represent? Encoding scheme gives meaning to bits
    • -
    • Order of bytes in memory: little endian versus big endian
    • -
    -
  • -
  • Bit manipulation – regardless of what bit vectors represent -
      -
    • - - - - - - - -
      Boolean algebra: bitwise operations => AND (&), OR (), XOR (^), NOT (~)
      -
    • -
    • Shift operations: left shift, right logical shift and right arithmetic shift -
        -
      • Logical shift: Fill x with y 0’s on left
      • -
      • Arithmetic shift: Fill x with y copies of x‘s sign bit on left
      • -
      • Sign bit: Most significant bit (MSb) before shifting occurred
      • -
      -
    • -
    -
  • -
- - - - - - - - - - -
NOTE: C logical operators and C bitwise (bit-level) operators behave differently! Watch out for && versus &, versus, …
- -

Next Lecture

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -
-
-
-
- - diff --git a/_site/melody/cmpt-295/03/03.html b/_site/melody/cmpt-295/03/03.html deleted file mode 100644 index 5c3a0fa..0000000 --- a/_site/melody/cmpt-295/03/03.html +++ /dev/null @@ -1,857 +0,0 @@ - - - - - | tait.tech - - - - - -
-
-

CMPT 295

- -

Unit - Data Representation

- -

Lecture 3 – Representing integral numbers in memory - unsigned and signed

- -

Last Lecture

-
    -
  • Von Neumann architecture -
      -
    • Architecture of most computers
    • -
    • Its components: CPU, memory, input and ouput, bus
    • -
    • One of its characteristics: Data and code (programs) both stored in memory
    • -
    -
  • -
  • A look at memory: defined byte-addressable memory, diagram of (compressed) memory -
      -
    • Word size (w): size of a series of bits (or bit vector) we manipulate, also size of machine words (see Section 2.1.2)
    • -
    -
  • -
  • A look at bits in memory -
      -
    • Why binary numeral system (0 and 1 -> two values) is used to represent information in memory
    • -
    • Algorithm for converting binary to hexadecimal (hex) -
        -
      1. Partition bit vector into groups of 4 bits, starting from right, i.e., least significant byte (LSB) -
          -
        • If most significant “byte” (MSB) does not have 8 bits, pad it: add 0’s to its left
        • -
        -
      2. -
      3. Translate each group of 4 bits into its hex value
      4. -
      -
    • -
    • What do bits represent? Encoding scheme gives meaning to bits
    • -
    • Order of bytes in memory: little endian versus big endian
    • -
    -
  • -
  • Bit manipulation – regardless of what bit vectors represent -
      -
    • Boolean algebra: bitwise operations => AND (&), OR (|), XOR (^), NOT (~)
    • -
    • Shift operations: left shift, right logical shift and right arithmetic shift -
        -
      • Logical shift: Fill x with y 0’s on left
      • -
      • Arithmetic shift: Fill x with y copies of x‘s sign bit on left
      • -
      • Sign bit: Most significant bit (MSb) before shifting occurred
      • -
      -
    • -
    -
  • -
- -

NOTE: C logical operators and C bitwise (bit-level) operators behave differently! Watch out for && versus &, || versus |, …

- -

Today’s Menu

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -

Warm up exercise!

- -

As a warm up exercise, fill in the blanks!

- -
    -
  • If the context is C (on our target machine) -
      -
    • char => _____ bits/ _____ byte
    • -
    • short => _____ bits/ _____ bytes
    • -
    • int => _____ bits/ _____ bytes
    • -
    • long => _____ bits/ _____ bytes
    • -
    • float => _____ bits/ _____ bytes
    • -
    • double => _____ bits/ _____ bytes
    • -
    • pointer (e.g. char *) => _____ bits/ _____ bytes
    • -
    -
  • -
- -

Unsigned integral numbers

- -

Remember:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size-1 
 
0x000301000010
0x000201101001
0x000101110100
0x000001110011
- -
    -
  • What if the byte at M[0x0002] represented an unsigned integral number, what would be its value? -x = a series of bits = bit vector -w = width of bit vector
  • -
  • - X=011010012,w=8X = 01101001_{2}, w=8 -
  • -
  • Let’s apply the encoding scheme:
  • -
- -

B2U(X)=i=0w1Xi×2i -\it \text{B2U}(X) = \sum_{i=0}^{w-1} X_{i} \times 2^i -

- -

Example: 0×27+1×26+1×25+0×24+1×23+0×22+1×20=0 \times 2^7 + 1 \times 2^6 + 1 \times 2^5 + 0 \times 2^4 + 1 \times 2^3 + 0 \times 2^2 + 1 \times 2^0 =

- -
    -
  • For w = 8, range of possible unsigned values: [ blank ]
  • -
  • For any w, range of possible unsigned values: [ blank ]
  • -
  • Conclusion: w bits can only represent a fixed # of possible values, but these w bits represent these values exactly
  • -
- -

B2U(X) Conversion (Encoding scheme)

-
    -
  • Positional notation: expand and sum all terms
  • -
- -

Decimal:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
did_{i}10i10^{i}
di1d_{i-1}10i110_{i-1}
d2d_{2}100
d1d_{1}10
d0d_{0}1
- -

Binary:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bib_{i}2i2^{i}
bi1b_{i-1}2i12^{i-1}
b2b_{2}4
b1b_{1}2
b0b_{0}1
- -

Remember: -B2U(X)=i=0w1Xi×2i -\it \text{B2U}(X) = \sum_{i=0}^{w-1} X_{i} \times 2^i -

- -

Example: 24610=2×102+4×101+6×100246_{10} = 2 \times 10^{2} + 4 \times 10^{1} + 6 \times 10^{0}

- -

Range of possible values?

- -
    -
  • If the context is C (on our target machine) -
      -
    • unsigned char?
    • -
    • unsigned short?
    • -
    • unsigned int?
    • -
    • unsigned long?
    • -
    -
  • -
- -

Examples of “Show your work”

- -

U2B(X) Conversion (into 8-bit binary # => w = 8)

- -

Method 1 - Using subtraction: subtracting decreasing power of 2 until reach 0:

- -

Starting number: 246

- -
    -
  • 246128=118246 – 128 = 118 -> 128=1×27128 = 1 \times 2^{7}
  • -
  • 11864=54118 – 64 = 54 -> 64=1×2664 = 1 \times 2^{6}
  • -
  • 5432=2254 – 32 = 22 -> 32=1×2532 = 1 \times 2^{5}
  • -
  • 2216=622 – 16 = 6 -> 16=1×2416 = 1 \times 2^{4}
  • -
  • 68=nop!6 – 8 = \text{nop!} -> 8=0×238 = 0 \times 2^{3}
  • -
  • 64=26 – 4 = 2 -> 4=1×224 = 1 \times 2^{2}
  • -
  • 22=02 – 2 = 0 -> 2=1×212 = 1 \times 2^{1}
  • -
  • 01=nop!0 – 1 = \text{nop!} -> 1=0×201 = 0 \times 2^{0}
  • -
  • - 24610=111101102246_{10} = 11110110_{2} -
  • -
- -

Method 2 - Using division: dividing by 2 until reach 0

- -

Start with 246

- -
    -
  • - 246÷2=123,R=0246 \div 2 = 123,R=0 -
  • -
  • - 123÷2=61,R=1123 \div 2 = 61,R=1 -
  • -
  • - 61÷2=30,R=161 \div 2 = 30,R=1 -
  • -
  • - 30÷2=15,R=030 \div 2 = 15,R=0 -
  • -
  • - 15÷2=7,R=115 \div 2 = 7,R=1 -
  • -
  • - 7÷2=3,R=17 \div 2 = 3,R=1 -
  • -
  • - 3÷2=1,R=13 \div 2 = 1,R=1 -
  • -
  • - 1÷2=0,R=11 \div 2 = 0,R=1 -
  • -
  • - 24610=111101102246_{10} = 11110110_{2} -
  • -
- -

U2B(X) Conversion – A few tricks

-
    -
  • Decimal -> binary -
      -
    • Trick: When decimal number is 2n, then its binary representation is 1 followed by n zero’s
    • -
    • Let’s try: if X = 32 => X = 25, then n = 5 => 100002 (w = 5) What if w = 8? Check: 1 x 24 = 32
    • -
    -
  • -
  • Decimal -> hex -
      -
    • Trick: When decimal number is 2n, then its hexadecimal representation is 2i followed by j zero’s, where n = i + 4j and 0 <= i <=3
    • -
    • Let try: if X = 8192 => X = 213, then n = 13 and 13 = i + 4j => 1 + 4 x 3 -=> 0x2000. Convert 0x2000 into a binary number: Check: 2 x 163 = 2 x 4096 = 8192
    • -
    -
  • -
- -

Signed integral numbers

- -

Remember:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size-1 
 
0x000301000010
0x000201101001
0x000101110100
0x000001110011
- -
    -
  • What if the byte at M[0x0001] represented a signed integral number, what would be its value?
  • -
  • X = 111101002 w = 8
  • -
  • T => Two’s Complement, w => width of the bit vector (annotation: first part of equaltion [everything before the plus sign] is the “sign bit”)
  • -
  • Let’s apply the encoding scheme:
  • -
- -

B2T(X)=xw1×2w1+i=0w2xi×2i -\it {B2T}(X) = -x_{w-1} \times 2^{w-1} + \sum_{i=0}^{w-2} x_{i} \times 2^{i} -

- -

Example: 1×27+1×26+1×25+1×24+0×23+1×22+0×21+0×20=?-1 \times 2^{7} + 1 \times 2^{6} + 1 \times 2^{5} + 1 \times 2^{4} + 0 \times 2^{3} + 1 \times 2^{2} + 0 \times 2^{1} + 0 \times 2^{0} = ?

- -
    -
  • What would be the bit pattern of the … -
      -
    • Most negative value:
    • -
    • Most positive value:
    • -
    -
  • -
  • For w = 8, range of possible signed values: [ blank ]
  • -
  • For any w, range of possible signed values: [ blank ]
  • -
  • Conclusion: same as for unsigned integral numbers
  • -
- -

Examples of “Show your work”

- -

T2B(X) Conversion -> Two’s Complement

- -

Annotation: w = 8

- -

Method 1: If X < 0, (~(U2B(|X|)))+1

- -

If X = -14 (and 8 bit binary #s)

- -
    -
  1. - X=>14=\lvert X\rvert => \lvert -14 \vert = -
  2. -
  3. U2B(14)\text{U2B}(14) =>
  4. -
  5. (first symbol is a tilde) (000011102)\sim(00001110_{2}) =>
  6. -
  7. (111100012)+1(11110001_{2})+1 =>
  8. -
- -

Binary addition:

-
-  11110001
-+ 00000001
-= ????????
-
- -

Method 2: If X = -14 (and 8 bit binary #s)

- -
    -
  1. - X+2w=>14+X + 2^{w} => -14 + -
  2. -
  3. U2B(242)\text{U2B}(242) =>
  4. -
- -

Using subtraction:

- -
    -
  1. 242128=114242 - 128 = 114 -> 1×271 \times 2^{7}
  2. -
  3. 11464=50114 - 64 = 50 -> 1×261 \times 2^{6}
  4. -
  5. 5032=1850 – 32 = 18 -> 1×251 \times 2^{5}
  6. -
  7. 1816=218 – 16 = 2 -> 1×241 \times 2^{4}
  8. -
  9. 28=nop!2 – 8 = \text{nop!} -> 0×230 \times 2^{3}
  10. -
  11. 24=nop!2 – 4 = \text{nop!} -> 0×220 \times 2^{2}
  12. -
  13. 22=02 – 2 = 0 -> 1×211 \times 2^{1}
  14. -
  15. 01=nop!0 – 1 = \text{nop!} -> 0×200 \times 2^{0}
  16. -
- -

Properties of unsigned & signed conversions

- -

Annotation: w = 4

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
XB2U(X)B2T(X)
000000
000111
001022
001133
010044
010155
011066
011177
10008-8
10019-7
101010-6
101111-5
110012-4
110113-3
111014-2
111115-1
- -
    -
  • Equivalence -
      -
    • Both encoding schemes (B2U and B2T ) produce the same bit patterns for nonnegative values
    • -
    -
  • -
  • Uniqueness -
      -
    • Every bit pattern produced by these encoding schemes (B2U and B2T) represents a unique (and exact) integer value
    • -
    • Each representable integer has unique bit pattern
    • -
    -
  • -
- -

Converting between signed & unsigned of same size (same data type)

- -
    -
  • Unsigned -
      -
    • w=8
    • -
    • if unsigned ux = 12910
    • -
    • U2T(X) = B2T(U2B(X))
    • -
    • then x = ???
    • -
    • Maintain Same Bit Pattern
    • -
    -
  • -
  • Signed (Two’s Complement) -
      -
    • w=4
    • -
    • if signed (2’s C) x=510x = -5_{10}
    • -
    • T2U(X) = B2U(T2B(X))
    • -
    • then unsigned ux = ???
    • -
    • Maintain Same Bit Pattern
    • -
    -
  • -
  • Conclusion - Converting between unsigned and signed numbers: -Both have same bit pattern, however, this bit pattern may be interpreted differently, i.e., producing a different value
  • -
- -

Converting signed to unsigned (and back) with w=4w = 4

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SignedBitsUnsignedNote
000000All rows from 0-7 inclusive can be converted from signed to unsigned with T2U(X), and unsigned to signed with U2T(X).
100011 
200102 
300113 
401004 
501015 
601106 
701117 
-810008All rows from here to 15 inclusive can be converted to the other like so: T2U(signed + 16/242^{4}) -> unsigned, U2T(unsigned - 16/242^{4}) -> signed.
-710019 
-6101010 
-5101111 
-4110012 
-3110113 
-2111014 
-1111115 
- -

Visualizing the relationship between signed & unsigned

-

If w=4,24=16w = 4, 2^{4} = 16

- -
    -
  • Signed (2’s Complement) Range: TMin to TMax (0 is the center)
  • -
  • Unsigned range: 0 to UMax (TMax is the center)
  • -
- -

Sign extension

-
    -
  • Converting unsigned (or signed) of different sizes (different data types) -
      -
    1. Small data type -> larger -
        -
      • Sign extension -
          -
        • Unsigned: zero extension
        • -
        • Signed: sign bit extension
        • -
        -
      • -
      -
    2. -
    -
  • -
  • Conclusion: Value unchanged
  • -
  • Let’s try: -
      -
    • Going from a data type that has a width of 3 bits (w = 3) to a data type that has a width of 5 bits (w = 5)
    • -
    -
  • -
  • Unsigned: X=3=0112,w=3X = 3 = 011_{2},w=3, X=4=1002,w=3X = 4 = 100_{2},w = 3 -
      -
    • New: X=?=?2,w=5X = ? = ?_{2},w=5, X=?+?2,w=5X = ? + ?_{2},w=5
    • -
    -
  • -
  • Signed: X=3=0112,w=3X = 3 = 011_{2},w=3, X=3=1012,w=3X=-3 = 101_{2},w=3 -
      -
    • New: X=?=?2,w=5X = ? = ?_{2},w=5, x=?=?2,w=5x = ? = ?_{2}, w=5
    • -
    -
  • -
- -

Truncation

- -
    -
  • Converting unsigned (or signed) of different sizes(different data types) -
      -
    1. Large data type -> smaller -
        -
      • Truncation
      • -
      -
    2. -
    -
  • -
  • Conclusion: Value may be altered -
      -
    • A form of overflow
    • -
    -
  • -
  • Let’s try: -
      -
    • Going from a data type that has a width of 5 bits (w = 5) to a data type that has a width of 3 bits (w = 3)
    • -
    -
  • -
  • Unsigned: X=27=110112,w=5X = 27 = 11011_{2},w = 5 -
      -
    • New: X=?=?2,w=3X = ? = ?_{2},w=3
    • -
    -
  • -
  • Signed: X=15=100012,w=3X = -15 = 10001_{2},w=3, X=1=111112,w=5X = -1 = 11111_{2}, w=5 -
      -
    • New: X=?=?2,w=3X = ? = ?_{2}, w=3, X=?=?2,w=3X = ? = ?_{2}, w=3
    • -
    -
  • -
- -

Summary

- -
    -
  • Interpretation of bit pattern B into either unsigned value U or signed value T -
      -
    • B2U(X) and U2B(X) encoding schemes (conversion)
    • -
    • B2T(X) and T2B(X) encoding schemes (conversion) -
        -
      • Signed value expressed as two’s complement => T
      • -
      -
    • -
    -
  • -
  • Conversions from unsigned <-> signed values -
      -
    • U2T(X) and T2U(X) => adding or subtracting 2w2^{w}
    • -
    -
  • -
  • Implication in C: when converting (implicitly via promotion and explicitly via casting): -
      -
    • Sign: -
        -
      • Unsigned <-> signed (of same size) -> Both have same bit pattern, however, this bit pattern may be interpreted differently -
          -
        • Can have unexpected effects -> producing a different value
        • -
        -
      • -
      -
    • -
    • Size: -
        -
      • Small -> large (for signed, e.g., short to int and for unsigned, e.g., unsigned short to unsigned int) -
          -
        • sign extension: For unsigned -> zeros extension, for signed -> sign bit extension
        • -
        • Both yield expected result –> resulting value unchanged
        • -
        -
      • -
      • Large -> small (e.g., unsigned int to unsigned short) -
          -
        • truncation: Unsigned/signed -> most significant bits are truncated (discarded)
        • -
        • May not yield expected results -> original value may be altered
        • -
        -
      • -
      -
    • -
    • Both (sign and size): 1) size conversion is first done then 2) sign conversion is done
    • -
    -
  • -
- -

Next Lecture

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -19 -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -
-
-
-
- - diff --git a/_site/melody/cmpt-295/03/Lecture_03_Data_Representation_Integers.pdf b/_site/melody/cmpt-295/03/Lecture_03_Data_Representation_Integers.pdf deleted file mode 100644 index bd146ef..0000000 Binary files a/_site/melody/cmpt-295/03/Lecture_03_Data_Representation_Integers.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/03/Lecture_03_Data_Representation_Integers.txt b/_site/melody/cmpt-295/03/Lecture_03_Data_Representation_Integers.txt deleted file mode 100644 index ba654c0..0000000 --- a/_site/melody/cmpt-295/03/Lecture_03_Data_Representation_Integers.txt +++ /dev/null @@ -1,781 +0,0 @@ -CMPT 295 -Unit - Data Representation - -Lecture 3 – Representing integral numbers in memory - unsigned and signed - -1 - - Last Lecture - Von Neumann architecture - Architecture of most computers - Its components: CPU, memory, input and ouput, bus - One of its characteristics: Data and code (programs) both stored in memory - A look at memory: defined byte-addressable memory, diagram of (compressed) memory - - Word size (w): size of a series of bits (or bit vector) we manipulate, also size of machine words -(see Section 2.1.2) - A look at bits in memory - Why binary numeral system (0 and 1 -> two values) is used to represent information in memory - Algorithm for converting binary to hexadecimal (hex) - -1. Partition bit vector into groups of 4 bits, starting from right, i.e., least significant byte (LSB) - If most significant “byte” (MSB) does not have 8 bits, pad it: add 0’s to its left -2. Translate each group of 4 bits into its hex value - - What do bits represent? Encoding scheme gives meaning to bits - Order of bytes in memory: little endian versus big endian - Bit manipulation – regardless of what bit vectors represent - Boolean algebra: bitwise operations => AND (&), OR (|), XOR (^), NOT (~) - Shift operations: left shift, right logical shift and right arithmetic shift - -2 - - Logical shift: Fill x with y 0’s on left - Arithmetic shift: Fill x with y copies of x‘s sign bit on left - Sign bit: Most significant bit (MSb) before shifting occurred - -NOTE: -C logical operators -and C bitwise (bit-level) -operators behave -differently! -Watch out for && versus -&, || versus |, … - - Today’s Menu - Representing data in memory – Most of this is review - “Under the Hood” - Von Neumann architecture - - Bits and bytes in memory - How to diagram memory -> Used in this course and other references - How to represent series of bits -> In binary, in hexadecimal (conversion) - What kind of information (data) do series of bits represent -> Encoding scheme - Order of bytes in memory -> Endian - - Bit manipulation – bitwise operations - Boolean algebra + Shifting - - Representing integral numbers in memory - Unsigned and signed - Converting, expanding and truncating - Arithmetic operations - - Representing real numbers in memory -3 - - IEEE floating point representation - Floating point in C – casting, rounding, addition, … - - Warm up exercise! -As a warm up exercise, fill in the blanks! - If the context is C (on our target machine) - char - -=> _____ bits/ _____ byte - - short => _____ bits/ _____ bytes - int - -=> _____ bits/ _____ bytes - - long - -=> _____ bits/ _____ bytes - - float => _____ bits/ _____ bytes - double=> _____ bits/ _____ bytes - pointer (e.g. char *) -4 - -=> _____ bits/ _____ bytes - - Remember: - -Unsigned integral numbers - What if the byte at M[0x0002] represented an unsigned integral -A series of bits -number, what would be its value? -=> bit vector -w =>width of - - X = 011010012 - -the bit vector - -w=8 - - Let’s apply the encoding scheme: - -B2U(X)  - -w1 - - xi 2 - -i - -i0 - -0 x 27 + 1 x 26 + 1 x 25 + 0 x 24 + 1 x 23 + 0 x 22 + 0 x 21 + 1 x 20 = - -5 - - For w = 8, range of possible unsigned values: [ - -] - - For any w, range of possible unsigned values: [ - -] - - Conclusion: w bits can only represent a fixed # of possible values, -but these w bits represent these values exactly - - B2U(X) Conversion (Encoding scheme) - Positional notation: expand and sum all terms - -••• - -10i - -2i - -10i-1 - -2i-1 - -100 -10 -1 - -4 -2 -1 - -••• - -di di-1 ••• d2 d1 d0 -Example: 24610 = 2 x 102 + 4 x 101 + 6 x 100 -6 - -1’s = 100 -10’s = 101 -100’s = 102 - -B2U(X )  - -w1 - - xi 2 -i0 - -i - - Range of possible values? - If the context is C (on our target machine) -unsigned char? -unsigned short? - -unsigned int? -unsigned long? - -7 - - Examples of “Show your work” - -U2B(X) Conversion (into 8-bit binary # => w = 8) - -8 - -Method 1 - Using subtraction: -subtracting decreasing -power of 2 until reach 0 -246 => 246 – 128 = 118 ->128 = 1 x 27 -118 – 64 = 54 --> 64 = 1 x 26 -54 – 32 = 22 --> 32 = 1 x 25 -22 – 16 = 6 --> 16 = 1 x 24 -6 – 8 = nop! -> 8 = 0 x 23 -6 – 4 =2 --> 4 = 1 x 22 -2– 2=0 --> 2 = 1 x 21 -0 – 1 = nop! -> 1 = 0 x 20 - -Method 2 - Using division: -dividing by 2 -until reach 0 -246 => 246 / 2 = 123 -> R = 0 -123 / 2 = 61 -> R = 1 -61 / 2 = 30 -> R = 1 -30 / 2 = 15 -> R = 0 -15 / 2 = 7 --> R = 1 -7/2 =3 --> R = 1 -3/2 =1 --> R = 1 -1/2 =0 --> R = 1 - -246 => 1 1 1 1 0 1 1 02 - -246 => 1 1 1 1 0 1 1 02 - - U2B(X) Conversion – A few tricks - Decimal -> binary - Trick: When decimal number is 2n, then its binary representation is 1 followed -by n zero’s - Let’s try: if X = 32 => X = 25, then n = 5 => 100002 (w = 5) - -What if w = 8? -Check: 1 x 24 = 32 - - Decimal -> hex - Trick: When decimal number is 2n, then its hexadecimal representation is 2i -followed by j zero’s, where n = i + 4j and 0 <= i <=3 - Let try: if X = 8192 => X = 213, then n = 13 and 13 = i + 4j => 1 + 4 x 3 -=> 0x2000 -9 - -Convert 0x2000 into a binary number: -Check: 2 x 163 = 2 x 4096 = 8192 - - Remember: - -Signed integral numbers - What if the byte at M[0x0001] represented a signed integral -number, what would be its value? T => Two’s Complement w =>width of -the bit vector - X = 111101002 w = 8 -w2 -w1 -i -B2T -(X -) - - -x -2 - -x -2 - -w1 -i - Let’s apply the encoding scheme: -Sign bit - -i0 - --1 x 27 + 1 x 26 + 1 x 25 + 1 x 24 + 0 x 23 + 1 x 22 + 0 x 21 + 0 x 20 = - - What would be the bit pattern of the … - Most negative value: - Most positive value: - -10 - - For w = 8, range of possible signed values: [ - -] - - For any w, range of possible signed values: [ - -] - - Conclusion: same as for unsigned integral numbers - - Examples of “Show your work” - -T2B(X) Conversion -> Two’s Complement -w=8 -Method 1 If X < 0, (~(U2B(|X|)))+1 - -Method 2 - -If X = -14 (and 8 bit binary #s) - -If X = -14 (and 8 bit binary #s) - -1. |X| => |-14| = - -1. - -2. U2B(14) => - -2. U2B(242) => - -3. ~(000011102) => -4. (111100012)+1 => -Binary addition: -11110001 -+ 00000001 -11 -Check: - -If X < 0, U2B(X + 2w) - -X + 2w => -14 + - -Using subtraction: - -242 – 128 = 114 -> 1 x 27 -114 – 64 = 50 -> 1 x 26 -50 – 32 = 18 --> 1 x 25 -18 – 16 = 2 --> 1 x 24 -2 – 8 -> nop! -> 0 x 23 -2 – 4 -> nop! -> 0 x 22 -2–2=0 --> 1 x 21 -0 – 1 -> nop! -> 0 x 20 - - Properties of unsigned & signed conversions -w=4 - -12 - -X -0000 -0001 -0010 -0011 -0100 -0101 -0110 -0111 -1000 -1001 -1010 -1011 -1100 -1101 -1110 -1111 - -B2U(X) -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 - -B2T(X) -0 -1 -2 -3 -4 -5 -6 -7 -–8 -–7 -–6 -–5 -–4 -–3 -–2 -–1 - - Equivalence - Both encoding schemes (B2U -and B2T ) produce the same bit -patterns for nonnegative values - Uniqueness - -Every bit pattern produced by -these encoding schemes (B2U -and B2T ) represents a unique -(and exact) integer value - - Each representable integer has -unique bit pattern - - Converting between signed & unsigned -of same size (same data type) -Unsigned - -w=8 - -ux - -If ux = 12910 -Signed (Two’s Complement) - -w=4 - -13 - -x - -If x = -510 - -U2T -U2B X - -B2T - -Maintain Same Bit Pattern - -then x = -Unsigned - -T2U - -T2B X - -Signed (Two’s Complement) -x - -B2U - -Maintain Same Bit Pattern - -ux - -then ux = - - Conclusion - Converting between unsigned and signed numbers: -Both have same bit pattern, however, this bit pattern may be interpreted -differently, i.e., producing a different value - - Converting signed  unsigned with w = 4 -Signed - -Bits - -Unsigned - -0 - -0000 - -0 - -1 - -0001 - -2 - -0010 - -2 - -3 - -0011 - -3 - -0100 - -4 - -5 - -0101 - -5 - -6 - -0110 - -6 - -7 - -0111 - -7 - --8 - -1000 - -8 - --7 - -1001 - -9 - --6 - -1010 - -10 - -4 - --5 - -U2T(X) - -+ 16 (+24) - --4 --3 - -14 - -14 - --2 --1 - -U2T(X) - -T2U(X) - -1 - -1011 - -T2U(X) - -11 - -1100 - -- 16 (+24) - -12 - -1101 - -13 - -1110 - -14 - -1111 - -15 - - Visualizing the relationship between -signed & unsigned -If w = 4, - -24 - -UMax -UMax – 1 - -= 16 - -TMax - -Signed -(2’s Complement) -Range -15 - -0 -–1 -–2 - -TMin - -TMax + 1 -TMax - -0 - -Unsigned -Range - - Sign extension - Converting unsigned (or signed) of different sizes (different data types) -1. Small data type -> larger - -Sign bit - - Sign extension - -X - -Unsigned: zero extension - -••• - -Signed: sign bit extension - - Conclusion: Value unchanged - -••• - -X - - Let’s try: - -••• - -••• - - Going from a data type that has a width of 3 bits (w = 3) to a data type -that has a width of 5 bits (w = 5) - Unsigned: X = 3 => -new X = -16 - - Signed: - -0112 w = 3 - -<= - -w=5 - -X = 3 => - -0112 w = 3 - -new X = - -<= - -w=5 - -X = 4 => -new X = - -1002 w = 3 - -<= - -w=5 - -X = -3 => - -1012 w = 3 - -new X = - -<= - -w=5 - - Truncation - Converting unsigned (or signed) of different sizes(different data types) - -2. Large data type -> smaller -••• - -X - - Truncation - -••• - - Conclusion: Value may be altered -A form of overflow - - Let’s try: - -X - -••• - - Going from a data type that has a width of 5 bits (w = 5) to a data type -that has a width of 3 bits (w = 3) - Unsigned: X = 27 => 110112 w = 5 - -new X = - Signed: -17 - -<= - -w=3 - -X = -15 => 100012 w = 5 - -new X = - -<= - -w=3 - -X = -1 => 111112 w = 5 -new X = - -<= - -w=3 - - Summary - Interpretation of bit pattern B into either unsigned value U or signed value T - B2U(X) and U2B(X) encoding schemes (conversion) - B2T(X) and T2B(X) encoding schemes (conversion) - Signed value expressed as two’s complement => T - - Conversions from unsigned <-> signed values - U2T(X) and T2U(X) => adding or subtracting 2w - - Implication in C: when converting (implicitly via promotion and explicitly via casting): - Sign: - Unsigned <-> signed (of same size) -> Both have same bit pattern, however, this bit pattern may - -be interpreted differently - - Can have unexpected effects -> producing a different value - - Size: - Small -> large (for signed, e.g., short to int and for unsigned, e.g., unsigned short to unsigned int) - sign extension: For unsigned -> zeros extension, for signed -> sign bit extension - Both yield expected result –> resulting value unchanged - - Large -> small (e.g., unsigned int to unsigned short) - truncation: Unsigned/signed -> most significant bits are truncated (discarded) - May not yield expected results -> original value may be altered - -18 - - Both (sign and size): 1) size conversion is first done then 2) sign conversion is done - - Next Lecture - Representing data in memory – Most of this is review - “Under the Hood” - Von Neumann architecture - - Bits and bytes in memory - How to diagram memory -> Used in this course and other references - How to represent series of bits -> In binary, in hexadecimal (conversion) - What kind of information (data) do series of bits represent -> Encoding scheme - Order of bytes in memory -> Endian - - Bit manipulation – bitwise operations - Boolean algebra + Shifting - - Representing integral numbers in memory - Unsigned and signed - Converting, expanding and truncating - Arithmetic operations - - Representing real numbers in memory -19 - - IEEE floating point representation - Floating point in C – casting, rounding, addition, … - - diff --git a/_site/melody/cmpt-295/04/04/index.html b/_site/melody/cmpt-295/04/04/index.html deleted file mode 100644 index 118a3d5..0000000 --- a/_site/melody/cmpt-295/04/04/index.html +++ /dev/null @@ -1,584 +0,0 @@ - - - - - | tait.tech - - - - - -
-
-

CMPT 295

- -

Unit - Data Representation

- -

Lecture 4 – Representing integral numbers in memory – Arithmetic operations

- -

Warm up question

-
    -
  • What is the value of … -
      -
    • TMin (in hex) for signed char in C: _________________
    • -
    • TMax (in hex) for signed int in C: _________________
    • -
    • TMin (in hex) for signed short in C: ________________
    • -
    -
  • -
- -

Last Lecture

-
    -
  • Interpretation of bit pattern B into either unsigned value U or signed value T -
      -
    • B2U(X) and U2B(X) encoding schemes (conversion)
    • -
    • B2T(X) and T2B(X) encoding schemes (conversion) -
        -
      • Signed value expressed as two’s complement => T
      • -
      -
    • -
    -
  • -
  • Conversions from unsigned <-> signed values -
      -
    • U2T(X) and T2U(X) => adding or subtracting 2w
    • -
    -
  • -
  • Implication in C: when converting (implicitly via promotion and explicitly via casting): -
      -
    • Sign: -
        -
      • Unsigned <-> signed (of same size) -> Both have same bit pattern, however, this bit pattern may be interpreted differently -
          -
        • Can have unexpected effects -> producing a different value
        • -
        -
      • -
      -
    • -
    • Size: -
        -
      • Small -> large (for signed, e.g., short to int and for unsigned, e.g., unsigned short to unsigned int) -
          -
        • sign extension: For unsigned -> zeros extension, for signed -> sign bit extension
        • -
        • Both yield expected result –> resulting value unchanged
        • -
        -
      • -
      • Large -> small (for signed, e.g., int to short and for unsigned, e.g., unsigned int to unsigned short) -
          -
        • truncation: Unsigned/signed -> most significant bits are truncated (discarded)
        • -
        • May not yield expected results -> original value may be altered
        • -
        -
      • -
      -
    • -
    • Both (sign and size): 1) size conversion is first done then 2) sign conversion is done
    • -
    -
  • -
- -

Today’s Menu

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -

Let’s first illustrate what we covered last lecture with a demo!

- -

Demo – Looking at size and sign conversions in C

- -
    -
  • What does the demo illustrate? -
      -
    • Size conversion: -
        -
      • Converting to a larger (wider) data type -> Converting short to int
      • -
      • Converting to a smaller (narrower) data type -> Converting short to char
      • -
      -
    • -
    • Sign conversion: -
        -
      • Converting from signed to unsigned -> Converting short to unsigned short
      • -
      • Converting from unsigned to signed -> Converting unsigned short to short
      • -
      -
    • -
    • Size and Sign conversion: -
        -
      • Converting from signed to unsigned larger (wider) data type -> Converting short to unsigned int
      • -
      • Converting from signed to unsigned smaller (narrower) data type -> -Converting short to unsigned char
      • -
      -
    • -
    -
  • -
  • This demo (code and results) posted on our course web site
  • -
- -

Integer addition (unlimited space)

- -
    -
  • -

    What happens when we add two decimal numbers? (Highlights show carring the one to complete the equation) -10710+93810=104510 -107_{10} + 938_{10} = 1045_{10}

    -
  • -
  • -

    Same thing happens when we add two binary numbers:

    -
  • -
- -

1011002+1011102=10110102 -101100_{2} + 101110_{2} = 1011010_{2} -

- -

Unsigned addition (limited space, i.e., fixed size in memory)

- -

What happens when we add two unsigned values?

- -w=8w=8 - -

a)

- -

Binary:

- -

001110112+010110102=? -\mathit{00111011}_{2} + \mathit{01011010}_{2} = ? -

- -

Decimal:

- -

5910+9010=14910 -\mathit{59}_{10} + {90}_{10} = {149}_{10} -

- -

b)

- -

Binary:

- -

101011102+110010112=? -\mathit{10101110}_{2} + \mathit{11001011}_{2} = ? -

- -

Decimal:

- -

17410+20310=37710 -174_{10} + 203_{10} = 377_{10} -

- -

Unsigned addition (+wu+^{u}_{w}) and overflow

- -
    -
  • True/expected sum is the result of integer addition with unlimited space.
  • -
  • Actual sum is the result of unsigned addition with limited space. Discarding the carry out bit.
  • -
  • Discarding carry out bit has same effect as applying modular arithmetic
  • -
- -

s=U+wuv=(u+v)mod2w -s = U+^{u}_{w}v = (u + v) \mod{2^{w}} -

- -
    -
  • Operands: w bits
  • -
  • True Sum: w+1 bits
  • -
- -

Closer look at unsigned addition overflow

- -
    -
  • w = 8 -> [0..255]
  • -
  • - 25510=111111112255_{10} = 11111111_{2} -
  • -
  • - 9010=01011010290_{10} = 01011010_{2} -
  • -
  • - 4510=00101101245_{10} = 00101101_{2} -
  • -
- -

Example 1:

- -

Decimal (carry out the 1 in 135):

- -

9010+4510=13510 -90_{10} + 45_{10} = 135_{10} -

- -

Binary (carry out the 1 in 10000111210000111_{2}):

- -

010110102+001011012=100001112 -01011010_{2} + 00101101_{2} = 10000111_{2} -

- -
    -
  • True sum, w=8: 10000111210000111_{2}
  • -
  • Actual (overflowed) sum, w=8: 100001112=1351010000111_{2} = 135_{10}
  • -
- -

Example 2:

- -

Decimal (carry 1 to the 3 in 300):

- -

25510+4510=30010 -255_{10} + 45_{10} = 300_{10} -

- -

Binary (carry the 1 at the beginning of the result):

- -

111111112+001011012=1001011002 -11111111_{2} + 00101101_{2} = 100101100_{2} -

- -
    -
  • True sum, w=9: 1001011002=30010100101100_{2} = 300_{10}
  • -
  • Actual (overflowed) sum, w=8: 001011002=441000101100_{2} = 44_{10}
  • -
- -

Comparing integer addition with Overflow: Effect of unsigned addition (w = 4)

- -

Annotation: with unlimited space:

- -

A 3d chart showing two numbers being added. -a and b on the z and x axies, the sum on the y axis. -y goes to a maximum height of 32 -(a = 15) + (b = 15) = (y = 30) -Annotation: With limited space (fixed-size memory):

- -

A 3d chart showing two numbers being added. -a and b on the z and x axies, the sum on the y axis. -y goes to a maximum height of 15 -(a = 15) + (b = 15) = (y = 14)

- -

An overflow occurs when there is a carry out

- -

For example: 15 (111121111_{2}) + 15 (111121111_{2}) = 30 (11110211110_{2}) as a true sum, and 14 (11110211110_{2}) as an actual sum.

- -

Signed addition (limited space, i.e., fixed size in memory)

- -

What happens when we add two signed values:

- -

w=8

- -

a)

- -

Binary: -001110112+010110102=?00111011_{2} + 01011010_{2} = ?

- -

Decimal: -5910+9010=1491059_{10} + 90_{10} = 149_{10}

- -

b)

- -

Binary: 101011102+110010112=?10101110_{2} + 11001011_{2} = ?

- -

Decimal: 8210+5310=13510-82_{10} + -53_{10} = -135_{10}

- -

Observation: Unsigned and signed additions have identical behavior @ the bit level, i.e., their sum have the same bit-level representation, but their interpretation differs

- -

Signed addition (+wt+^{t}_{w}) and overflow

- -

True sum would be the result of integer addition with unlimited space: -Actual sum is the result of signed addition with limited space:

- -

Operands: w bits -True Sum: w+1 bits

- -

After discarduing carry out bit: w bits (overflow)

- -
    -
  • Discarding carry out bit has same effect as applying modular arithmetic
  • -
- -

s=u+wtv=U2Tw[(u+v)mod2w] -s = u +^{t}_{w} v = \text{U2T}_{w}[(u + v) \mod 2^{w}] -

- -

Negative overflow and positive overflows are possible. -Diagram showing negative overflows becoming positive, and positive overflows becoming negative.

- -

Closer look at signed addition overflow

-
    -
  • w = 8 -> [-128..127]
  • -
  • - 9010=01011010290_{10} = 01011010_{2} -
  • -
  • - 4510=00101101245_{10} = 00101101_{2} -
  • -
  • - 4510=110100112-45_{10} = 11010011_{2} -
  • -
  • - 9010=101001102-90_{10} = 10100110_{2} -
  • -
- -

Example 1:

- -

Decimal: 9010+4510=1351090_{10} + 45_{10} = 135_{10}

- -

Binary: 010110102+001011012=010000111201011010_{2} + 00101101_{2} = 010000111_{2}

- -

The binary result is -121

- -

Example 2:

- -

Decimal: 9010+4510=13510-90_{10} + -45_{10} = -135_{10}

- -

Binary: 101001102+110100112=101111001210100110_{2} + 11010011_{2} = 101111001_{2}

- -

Binary result is 121

- -

Example 3:

- -

Decimal: 9010+4510=4510-90_{10} + 45_{10} = -45_{10}

- -

Binary: 101001102+001011012=011010011210100110_{2} + 00101101_{2} = 011010011_{2}

- -

Example 4:

- -

Decimal: 9010+4510=451090_{10} + -45_{10} = 45_{10}

- -

Binary: 010110102+110100112=100101101201011010_{2} + 11010011_{2} = 100101101_{2}

- -

A chart showing the relationship between true sum and actual (overflowed) sum. -Actual sum has a possible value between 127 to -128. -A true sum, however has a range between 255 and -256. -As your true sum goes further down from -128, its actual sum becomes lower as well. Starting at -129 = 127. -As you true sum goes futher up from 127, the actual sum also rises, satrting with 128 = -128.

- -

Visualizing signed addition overflow (w = 4)

- -

A 3D chart which has its x axis go from -8 to +7, its z axis go from -8 to +6, and a y axis which goes from :wq

- -

Positive Overflow

- -

For example: 7 (011120111_{2}) + 1 (000120001_{2}) = 8 (100021000_{2}) is the true sum and = -8 (100021000_{2}) is the actual sum

- -

What about subtraction? -> Addition

- -

x + (-x) = 0

- -
    -
  • Subtracting a number is equivalent to adding its additive inverse -
      -
    • Instead of subtracting a positive number, we could add its negative version:
    • -
    -
  • -
- -

107118=11 -107 - 118 = -11 -

- -

becomes:

- -

107+(118)=18 -107 + (-118) = -18 -

- -
    -
  • Let‘s try:
  • -
- -

Decimal:

- -1071011810=11107_{10} - 118_{10} = -11 - -

Binary:

- -011010112011101102=01101011_{2} - 01110110_{2} = - -

Binary subtraction by addition:

- -011010112+100010102=11110101201101011_{2} + 10001010_{2} = 11110101_{2} - -

Binary subtraction by addition is equal to -11

- -

Check: 128+64+32+16+4+1=1110-128 + 64 + 32 + 16 + 4 + 1 = -11_{10}

- -

T2B(X) conversion:

-
    -
  1. - ( (U2B(X)))+1(~(\text{U2B}(|X|)))+1 -
  2. -
  3. - ( (U2B(118)))+1(~(\text{U2B}(|-118|)))+1 -
  4. -
  5. - ( (U2B(118)))+1(~(\text{U2B}(118)))+1 -
  6. -
  7. - ((011101102))+1(\sim(01110110_{2}))+1 -
  8. -
  9. - (100010012)+1(10001001_{2})+1 -
  10. -
  11. - 10001010210001010_{2} -
  12. -
- -

Multiplication (wu,wt*^{u}_{w}, *^{t}_{w}) and overflow

- -

True product would be the result of integer multiplication with unlimited space: expected product -Actual product is the result of multiplication with limited space.

- -
    -
  • Operands: w bits
  • -
  • True Product: 2w bits u×vu \times v
  • -
  • -

    Discard: w bits

    -
  • -
  • Discarding high order w bits has same effect as applying modular arithmetic
  • -
- -p=uwuv=(u×v)mod2wp = u *^{u}_{w}v = (u \times v) \mod 2^{w} - -p=uwtv=U2Tw[(u×v)mod2w]p = u *^{t}_{w}v = \text{U2T}_{w}[(u \times v) \mod 2^{w}] - -
    -
  • Example: w = 4
  • -
- -

Decimal:

- -510×510=25105_{10} \times 5_{10} = 25_{10} - -

Binary:

- -01012×01012=001100120101_{2} \times 0101_{2} = \sout{001}1001_{2} - -

Multiplication with power-of-2 versus shifting

- -
    -
  • If x×yx \times y where y=2ky = 2^{k} then x << k -
      -
    • For both signed and unsigned
    • -
    -
  • -
  • Example: -
      -
    • x×8=x×23x \times 8 = x \times 2^{3} = x << 3
    • -
    • x×24=(x×25)(x×23)=(x×32)(x×8)x \times 24 = (x \times 25) – (x \times 23) = (x \times 32) – (x \times 8) = (x « 5) – (x « 3) (decompose 24 in powers of 2 => 32 – 8)
    • -
    -
  • -
  • Most machines shift and add faster than multiply -
      -
    • We’ll soon see that compiler generates this code automatically -17
    • -
    -
  • -
- -

Summary

- -
    -
  • Demo of size and sign conversion in C: code and results posted!
  • -
  • Addition: -
      -
    • Unsigned/signed: -
        -
      • Behave the same way at the bit level
      • -
      • Interpretation of resulting bit vector (sum) may differ
      • -
      -
    • -
    • Unsigned addition -> may overflow, i.e., (w+1)th bit is set -
        -
      • If so, then actual sum obtained => (x+y)mod2w(x + y) \mod 2^{w}
      • -
      -
    • -
    • Signed addition -> may overflow, i.e., (w+1)th bit is set -
        -
      • If so, then true sum may be too +ve -> positive overflow OR too -ve -> negative overflow
      • -
      • Then actual sum obtained => U2Tw[(x+y)mod2w]\text{U2T}_{w}[(x + y) \mod 2^{w}]
      • -
      -
    • -
    -
  • -
  • Subtraction -
      -
    • Becomes an addition where negative operands are transformed into their additive inverse (in two’s complement)
    • -
    -
  • -
  • Multiplication: -
      -
    • Unsigned: actual product obtained -> (x×y)mod2w(x \times y) \mod 2^{w}
    • -
    • Signed: actual product obtained -> $$\text{U2T}_{w}[(x \times y) \mod 2^{w}]
    • -
    • Can be replaced by additions and shifts
    • -
    -
  • -
- -

Next lecture

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -

We’ll illustrate what we covered today by having a demo!

- -
-
-
-
- - diff --git a/_site/melody/cmpt-295/04/Lecture_04_Data_Representation_Integers.pdf b/_site/melody/cmpt-295/04/Lecture_04_Data_Representation_Integers.pdf deleted file mode 100644 index 482f040..0000000 Binary files a/_site/melody/cmpt-295/04/Lecture_04_Data_Representation_Integers.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/04/Lecture_4_Demo.c b/_site/melody/cmpt-295/04/Lecture_4_Demo.c deleted file mode 100644 index 69cd8b9..0000000 --- a/_site/melody/cmpt-295/04/Lecture_4_Demo.c +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include -#include - - -typedef unsigned char *byte_pointer; - -void show_bytes(byte_pointer start, size_t len) { - int i; - - for ( i = len-1; i >= 0; i--) - printf(" %.2x", start[i]); - - return; -} - -int main(int argc, char *argv[]) { - - if ( argc < 2 ) { - printf("Forgot the argment! Try again!\n"); - return 1; - } - - short aShort = atoi(argv[1]); - - printf("\nAs a short data type, the variable aShort has the value %hd (hex: 0x", aShort); - show_bytes((byte_pointer) &aShort, sizeof(short)); - printf(")\n\n"); - - - /* Convert - size - implicitly */ - printf("Converting SIZE implicitly: short -> integer *** Sign extension ***\n"); - printf("This is done by issuing the statement: int anInt = aShort;\n"); - int anInt = aShort; - printf("As a int data type, the variable anInt has the value %d (hex: 0x", anInt); - show_bytes((byte_pointer) &anInt, sizeof(int)); - printf(")\n\n"); - - /* Convert - size - implicitly */ - printf("Converting SIZE implicitly: short -> char *** Truncation ***\n"); - printf("This is done by issuing the statement: signed char aChar = aShort;\n"); - signed char aChar = aShort; - printf("As a char data type, the variable aChar has the value %hhi (hex: 0x", aChar); - show_bytes((byte_pointer) &aChar, sizeof(signed char)); - printf(")\n\n"); - - /* Convert - sign - implicitly*/ - printf("Converting SIGN implicitly: short -> unsigned short\n"); - printf("This is done by issuing the statement: unsigned short aUShort = aShort;\n"); - unsigned short aUShort = aShort; - printf("As an unsigned short data type, the variable aUShort has the value %hu (hex: 0x", aUShort); - show_bytes((byte_pointer) &aUShort, sizeof(unsigned short)); - printf(")\n\n"); - - /* Convert - sign - implicitly*/ - printf("Converting SIGN implicitly: unsigned short -> short\n"); - printf("This is done by issuing the statement: short aShort1 = aUShort;\n"); - short aShort1 = aUShort; - printf("As a signed short data type, the variable aShort1 has the value %hi (hex: 0x", (signed short) aShort1); - show_bytes((byte_pointer) &aShort1, sizeof(signed short)); - printf(")\n\n"); - - /* Convert - both: 1) size, 2) sign */ - printf("Converting both SIZE and SIGN: short -> unsigned int\n"); - printf("This is done by issuing the statement: unsigned aUInt = aShort;\n"); - unsigned aUInt = aShort; - printf("As an unsigned int data type, the variable aUInt has the value %u (hex: 0x", aUInt); - show_bytes((byte_pointer) &aUInt, sizeof(unsigned)); - printf(")\n\n"); - - /* One step at a time */ - printf("One step at a time - First conversion is SIZE: (int) aShort = %d\n", (int) aShort); - printf("One step at a time - Second conversion is SIGN: (unsigned) (int) aShort = %u\n\n", (unsigned) (int) aShort); - - /* Reverse the process and see what happens ... */ - printf("What if ... First conversion is SIGN: (unsigned short) aShort = %hu\n", (unsigned short) aShort); - printf("What if ... Second conversion is SIZE: (unsigned int) (unsigned short) aShort = %d\n\n", (unsigned int) (unsigned short) aShort); - - /* Convert - both: 1) size, 2) sign */ - printf("Converting both SIZE and SIGN: short -> unsigned char\n"); - printf("This is done by issuing the statement: unsigned char anUChar = aShort;\n"); - unsigned char anUChar = aShort; - printf("As an unsigned char data type, the variable anUChar has the value %hhu (hex: 0x", anUChar); - show_bytes((byte_pointer) &anUChar, sizeof(unsigned char)); - printf(")\n\n"); - - /* One step at a time */ - printf("One step at a time - First conversion is SIZE: (signed char) aShort = %hhi\n", (signed char) aShort); - printf("One step at a time - Second conversion is SIGN: (unsigned char) (signed char) aShort = %hhu\n\n", (unsigned char) (signed char) aShort); - - /* Reverse the process and see what happens ... */ - printf("What if ... First conversion is SIGN: (unsigned short) aShort = %hu\n", (unsigned short) aShort); - printf("What if ... Second conversion is SIZE: (unsigned char) (unsigned short) aShort = %hhu\n\n", (unsigned char) (unsigned short) aShort); - - return 0; - -} \ No newline at end of file diff --git a/_site/melody/cmpt-295/04/Lecture_4_Demo_RESULTS.txt b/_site/melody/cmpt-295/04/Lecture_4_Demo_RESULTS.txt deleted file mode 100644 index a00e1ac..0000000 --- a/_site/melody/cmpt-295/04/Lecture_4_Demo_RESULTS.txt +++ /dev/null @@ -1,81 +0,0 @@ -$ ./Demo 12345 - -As a short data type, the variable aShort has the value 12345 (hex: 0x 30 39) - -Converting SIZE implicitly: short -> integer *** Sign extension *** -This is done by issuing the statement: int anInt = aShort; -As a int data type, the variable anInt has the value 12345 (hex: 0x 00 00 30 39) - -Converting SIZE implicitly: short -> char *** Truncation *** -This is done by issuing the statement: signed char aChar = aShort; -As a char data type, the variable aChar has the value 57 (hex: 0x 39) - -Converting SIGN implicitly: short -> unsigned short -This is done by issuing the statement: unsigned short aUShort = aShort; -As an unsigned short data type, the variable aUShort has the value 12345 (hex: 0x 30 39) - -Converting SIGN implicitly: unsigned short -> short -This is done by issuing the statement: short aShort1 = aUShort; -As a signed short data type, the variable aShort1 has the value 12345 (hex: 0x 30 39) - -Converting both SIZE and SIGN: short -> unsigned int -This is done by issuing the statement: unsigned aUInt = aShort; -As an unsigned int data type, the variable aUInt has the value 12345 (hex: 0x 00 00 30 39) - -One step at a time - First conversion is SIZE: (int) aShort = 12345 -One step at a time - Second conversion is SIGN: (unsigned) (int) aShort = 12345 - -What if ... First conversion is SIGN: (unsigned short) aShort = 12345 -What if ... Second conversion is SIZE: (unsigned int) (unsigned short) aShort = 12345 - -Converting both SIZE and SIGN: short -> unsigned char -This is done by issuing the statement: unsigned char anUChar = aShort; -As an unsigned char data type, the variable anUChar has the value 57 (hex: 0x 39) - -One step at a time - First conversion is SIZE: (signed char) aShort = 57 -One step at a time - Second conversion is SIGN: (unsigned char) (signed char) aShort = 57 - -What if ... First conversion is SIGN: (unsigned short) aShort = 12345 -What if ... Second conversion is SIZE: (unsigned char) (unsigned short) aShort = 57 - ----------------------------------------------------------------------------------------------- - -$ ./Demo -12345 - -As a short data type, the variable aShort has the value -12345 (hex: 0x cf c7) - -Converting SIZE implicitly: short -> integer *** Sign extension *** -This is done by issuing the statement: int anInt = aShort; -As a int data type, the variable anInt has the value -12345 (hex: 0x ff ff cf c7) - -Converting SIZE implicitly: short -> char *** Truncation *** -This is done by issuing the statement: signed char aChar = aShort; -As a char data type, the variable aChar has the value -57 (hex: 0x c7) - -Converting SIGN implicitly: short -> unsigned short -This is done by issuing the statement: unsigned short aUShort = aShort; -As an unsigned short data type, the variable aUShort has the value 53191 (hex: 0x cf c7) - -Converting SIGN implicitly: unsigned short -> short -This is done by issuing the statement: short aShort1 = aUShort; -As a signed short data type, the variable aShort1 has the value -12345 (hex: 0x cf c7) - -Converting both SIZE and SIGN: short -> unsigned int -This is done by issuing the statement: unsigned aUInt = aShort; -As an unsigned int data type, the variable aUInt has the value 4294954951 (hex: 0x ff ff cf c7) - -One step at a time - First conversion is SIZE: (int) aShort = -12345 -One step at a time - Second conversion is SIGN: (unsigned) (int) aShort = 4294954951 - -What if ... First conversion is SIGN: (unsigned short) aShort = 53191 -What if ... Second conversion is SIZE: (unsigned int) (unsigned short) aShort = 53191 - -Converting both SIZE and SIGN: short -> unsigned char -This is done by issuing the statement: unsigned char anUChar = aShort; -As an unsigned char data type, the variable anUChar has the value 199 (hex: 0x c7) - -One step at a time - First conversion is SIZE: (signed char) aShort = -57 -One step at a time - Second conversion is SIGN: (unsigned char) (signed char) aShort = 199 - -What if ... First conversion is SIGN: (unsigned short) aShort = 53191 -What if ... Second conversion is SIZE: (unsigned char) (unsigned short) aShort = 199 \ No newline at end of file diff --git a/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.html b/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.html deleted file mode 100644 index 0bcdb4d..0000000 --- a/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.html +++ /dev/null @@ -1,761 +0,0 @@ - - - - - | tait.tech - - - - - -
-
-

CMPT 295: Unit - Data Representation

- -

Lecture 5

- -
    -
  • Representing fractional numbers in memory
  • -
  • IEEE floating point representation
  • -
- -

Last Lecture

-
    -
  • Demo of size and sign conversion in C: code and results posted!
  • -
  • Addition: -
      -
    • Unsigned/signed: -
        -
      • Behave the same way at the bit level
      • -
      • Interpretation of resulting bit vector (sum) may differ
      • -
      -
    • -
    • Unsigned addition -> true sum may overflow its w bits in memory (annotation with diagram of unisnged overflows, see lecture 04 to see full description of diagram) -
        -
      • If so, then actual sum = (x+y)mod2w(x + y) \mod 2^{w} (equivalent to subtracting 2w2^{w} from true sum (x+y)(x + y))
      • -
      -
    • -
    • Signed addition -> true sum may overflow its w bits in memory (annotation attached displaying diagram of negative and positive overflows, see Lecture 04 for detailed description of diagram) -
        -
      • If so then … -
          -
        • actual sum = U2Tw[(x+y)mod2w]\text{U2T}_{w}[(x + y) \mod 2^{w}]
        • -
        • true sum may be too +ve -> positive overflow OR too –ve -> negative overflow
        • -
        -
      • -
      -
    • -
    -
  • -
  • Subtraction -
      -
    • Becomes an addition where the 2nd operand is transformed into its additive inverse in two’s complement
    • -
    -
  • -
  • Multiplication: -
      -
    • Unsigned: actual product = (x×y)mod2w(x \times y) \mod 2^{w}
    • -
    • Signed: actual product = U2Tw[(x×y)mod2w]\text{U2T}_{w}[(x \times y) \mod 2^{w}]
    • -
    • Can be replaced by additions and shifts
    • -
    -
  • -
- -

Conclusion: the same bit pattern is interpreted differently.

- -

Questions

- -
    -
  • Why are we learning this?
  • -
  • What can we do in our program when we suspect that overflow may occur?
  • -
- -

Demo – Looking at integer additions in C

-
    -
  • What does the demo illustrate? -
      -
    • Unsigned addition -
        -
      • Without overflow
      • -
      • With overflow
      • -
      • Can overflow be predicted?
      • -
      -
    • -
    • Signed addition -
        -
      • Without overflow
      • -
      • With positive overflow and negative overflow
      • -
      • Can overflow be predicted?
      • -
      -
    • -
    -
  • -
  • This demo (code and results) posted on our course web site -4
  • -
- -

Today’s Menu

-
    -
  • (greyed out) Representing data in memory – Most of this is review -
      -
    • (greyed out) “Under the Hood” - Von Neumann architecture
    • -
    • (greyed out) Bits and bytes in memory -
        -
      • (greyed out) How to diagram memory -> Used in this course and other references
      • -
      • (greyed out) How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • (greyed out) What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • (greyed out) Order of bytes in memory -> Endian
      • -
      -
    • -
    • (greyed out) Bit manipulation – bitwise operations -
        -
      • (greyed out) Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • (greyed out) Representing integral numbers in memory -
      -
    • (greyed out) Unsigned and signed
    • -
    • (greyed out) Converting, expanding and truncating
    • -
    • (greyed out) Arithmetic operations
    • -
    -
  • -
  • (highlighted) Representing real numbers in memory
  • -
  • (highlighted) IEEE floating point representation
  • -
  • (greyed out) Floating point in C – casting, rounding, addition, …
  • -
- -

We’ll illustrate what we covered today by having a demo!

- -

Converting a fractional decimal number into a binary number (bit vector) [R2B(X)]

- -
    -
  • How would 346.625 (34658346 \frac{5}{8}) be represented as a binary number?
  • -
  • Expanding the subtraction method we have already seen:
  • -
- -

Starting number: 346.625

- -

Whole:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ValueAttempted Addition (subtraction) valueResultBinary ImplicationNote
346-256901×281 \times 2^{8}MSb
90-1280×270 \times 2^{7} 
90-64261×261 \times 2^{6} 
26-320×250 \times 2^{5} 
26-16101×241 \times 2^{4} 
10-821×231 \times 2^{3} 
2-40×220 \times 2^{2} 
2-201×211 \times 2^{1} 
0-10×210 \times 2^{1}LSb
- -

Fractional:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ValueAttempted addition (subtraction) valueresultbinary implicationnotes
.625-0.5.1251×211 \times 2^{-1}MSb
.125-0.250×220 \times 2^{-2} 
.125-0.12501×231 \times 2^{-3}LSb
- -

Binary representation is: 101011010.1012101011010.101_{2}

- -

First, last binary digit before the period are MSb, LSb respectively. -First, last binary digit after the period are also MSb, LSb respectively.

- -

Negative Powers of 2:

- -
    -
  • 212^{-1} = 0.5
  • -
  • 222^{−2} = 0.25
  • -
  • 232^{−3} = 0.125
  • -
  • 242^{−4} = 0.0625
  • -
  • 252^{−5} = 0.03125
  • -
- -

Converting a binary number into a fractional decimal number [R2B(X)]

- -
    -
  • How would 1011.10121011.101_{2} be represented as a fractional decimal number?
  • -
- -

Review: Fractional decimal numbers

- -

Positional notation:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NotationValue
did_{i}10i10^{i}
di1d_{i-1}10i110^{i-1}
d2d_{2}100
d1d_{1}10
d0d_{0}1
d1d_{-1}110\frac{1}{10}
d2d_{-2}1100\frac{1}{100}
d3d_{-3}11000\frac{1}{1000}
djd_{-j}10j10^{-j}
- -

Example: 2.345

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Digit in numberNote
210010^{0}
. 
310110^{-1}
410210^{-2}
510310^{-3}
- -

2.345=2×100+3×101+4×102+5×103 -2.345 = 2 \times 10^{0} + 3 \times 10^{−1} + 4 \times 10^{−2} + 5 \times 10^{−3} -

- -

Converting a binary number into a fractional decimal number [B2R(X)]

- -

Positional notation: can this be a possible encoding scheme?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bib_{i}2i2^{i}
bi1b_{i-1}2i12^{i-1}
b2b_{2}4
b1b_{1}2
b0b_{0}1
b1b_{-1}12\frac{1}{2}
b2b_{-2}14\frac{1}{4}
b3b_{-3}18\frac{1}{8}
bjb_{-j}2j2^{-j}
- -

Converting a binary number into a fractional decimal number [B2R(X)]

- -
    -
  • How would 1011.10121011.101_{2} be represented as a fractional decimal number?
  • -
  • Using the positional encoding scheme:
  • -
- -

1011.1012=(10112=1×23+1×21+1×20=1110)+(.1012=1×21+1×23=0.5+0.125=0.62510) -1011.101_{2} = \\ -(1011_{2} = 1 \times 2^{3} + 1 \times 2^{1} + 1 \times 2^{0} = 11_{10}) +\\ -(.101_{2} = 1 \times 2^{-1} + 1 \times 2^{-3} = 0.5 + 0.125 = 0.625_{10}) -

- -

Result: ____

- -

Negative Powers of 2

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212^{−1}0.5
222^{−2}0.25
232^{−3}0.125
242^{−4}0.0625
252^{−5}0.03125
262^{−6}0.015625
272^{−7}0.0078125
282^{−8}0.00390625
- -

Positional notation as encoding scheme?

- -
    -
  • One way to answer this question is to investigate whether the encoding scheme allows for arithmetic operations
  • -
  • Let’s see: Using the positional notation as an encoding scheme produces fractional binary numbers that can be -
      -
    • added
    • -
    • multiplied by 2 by shifting left
    • -
    • divided by 2 by shifting right (unsigned)
    • -
    -
  • -
- -

Example:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OperandBinaryFractionMakeup
 1011.10121011.101_{2}115811\frac{5}{8}8+2+1+12+188 + 2 + 1 + \frac{1}{2} + \frac{1}{8}
Divide by 2101.11012101.1101_{2}513165\frac{13}{16}4+1+12+14+1164 + 1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{16}
Divide by 210.11101210.11101_{2}229322\frac{29}{32}2+12+14+18+1322 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{32}
Multiply by 41011.10121011.101_{2}115811\frac{5}{8}8+2+1+12+188 + 2 + 1 + \frac{1}{2} + \frac{1}{8}
Multiply by 210111.01210111.01_{2}231423\frac{1}{4}16+4+2+1+1416 + 4 + 2 + 1 + \frac{1}{4}
- -

So far so good! 

- -

Positional notation as encoding scheme?

- -
    -
  • Advantage (so far): -
      -
    • Straightforward arithmetic: can shift to multiply and divide, convert
    • -
    -
  • -
  • Disadvantage: -
      -
    • Cannot encode all fractional numbers: -
        -
      • Can only represent numbers of the form x÷2kx \div 2^{k} (what about 15\frac{1}{5} or -34.8)
      • -
      -
    • -
    • Only one setting of binary point within the w bits -> this limits the range of possible values -
        -
      • What is this range? -
          -
        • Example: w = 32 bits and binary point located at 16th bit: -
            -
          • Whole number range: [0 .. 131071]
          • -
          • Fraction range: [0 .. 1 - ε]
          • -
          • Range: [0.0 … 131071.99999]
          • -
          -
        • -
        -
      • -
      -
    • -
    -
  • -
- -

Not so good anymore!

- -

Representing fractional numbers in memory

- -
    -
  • Here is another possible encoding scheme: IEEE floating point representation (IEEE Standard 754)
  • -
  • Overview: -
      -
    • Binary Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E} -
        -
      • s – Sign bit -> determines whether number is negative or positive
      • -
      • M – Significand (or Mantissa) -> fractional part of number
      • -
      • E – Exponent
      • -
      -
    • -
    -
  • -
  • Form of bit pattern (number of items not important, focus on scale): [s|eee|fffffffffffff] -
      -
    • Most significant bit (MSb) s (similar to sign-magnitude encoding)
    • -
    • exp (e) field encodes E (but is not equal to E)
    • -
    • frac (f) field encodes M (but is not equal to M)
    • -
    -
  • -
- -

IEEE Floating Point Representation – Precision options

- -
    -
  • Single precision: 32 bits ≈ 7 decimal digits, range:10±38 -
      -
    • In C: diagram of memory showing: -
        -
      • 1 sign bit
      • -
      • 8 exp bits
      • -
      • 23 frac bits
      • -
      -
    • -
    -
  • -
  • Double precision: 64 bits ≈ 16 decimal digits, range:10±308 -
      -
    • In C: diagram of memory showing: -
        -
      • 1 sign bit
      • -
      • 11 exp bits
      • -
      • 52 frac bits
      • -
      -
    • -
    -
  • -
- -

IEEE Floating Point Representation – Three “kinds” of values

- -

Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E}

- -
    -
  • 1 sign bit
  • -
  • k exp bits -
      -
    • denormalized: 00…00 (all 0’s)
    • -
    • normalized: exp != 0 and exp != 11..11
    • -
    • special cases: 11…11 (all 1’s)
    • -
    -
  • -
  • -

    n frac bits

    -
  • -
  • E = exp - bias, bias = 2k112^{k-1} -1
  • -
  • M = 1 + frac
  • -
- -

Why is E biased? Using single precision as an example:

- -
    -
  • exp range: [00000001 .. 11111110] and bias = 28112^{8-1} – 1
  • -
  • E range: [-126 .. 127]
  • -
  • If no bias: E range: [1 .. 254] => 212^{1} to 22542^{254}
  • -
- -

Why adding 1 to frac? Because number V is first normalized before it is converted.

- -

Review: Scientific Notation and normalization

- -
    -
  • From Wikipedia: -
      -
    • Scientific notation is a way of expressing numbers that are too large or too small (usually would result a long string of digits) to be conveniently written in decimal form.
    • -
    • In scientific notation, nonzero numbers are written in the form
    • -
    • In normalized notation, the exponent n is chosen so that the absolute value of the significand m is at least 1 but less than 10.
    • -
    -
  • -
  • Examples: -
      -
    • A proton’s mass is 0.0000000000000000000000000016726 kg -> 1.6726×10271.6726 \times 10^{−27}kg
    • -
    • Speed of light is 299,792,458 m/s -> 2.99792,458×1082.99792,458 \times 10^{8} m/s
    • -
    -
  • -
- -

Syntax:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NotationName
+/−sign
d0d_{0}, d1d_{-1}, d2d_{-2}, d3d_{-3}dnd_{-n}significand
×times
bbase
exp^{exp}exponent
- -

Let’s try: 101011010.1012101011010.101_{2} = ____

- -

Summary

- -
    -
  • Representing integral numbers (signed/unsigned) in memory: -
      -
    • Encode schemes allow for small range of values exactly
    • -
    -
  • -
  • Representing fractional numbers in memory: -
      -
    1. Positional notation (advantages and disadvantages)
    2. -
    3. IEEE floating point representation: wider range, mostly approximately
    4. -
    -
  • -
  • Overview of IEEE Floating Point representation
  • -
  • - V=(1)s×M×2EV = (-1)^{s} \times M \times 2^{E} -
  • -
  • Precision options
  • -
  • 3 kinds: normalized, denormalized and special values
  • -
- -

Today’s Menu

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -18 -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -
-
-
-
- - diff --git a/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.pdf b/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.pdf deleted file mode 100644 index 44cf646..0000000 Binary files a/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers/index.html b/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers/index.html deleted file mode 100644 index dacf722..0000000 --- a/_site/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers/index.html +++ /dev/null @@ -1,764 +0,0 @@ - - - - - | tait.tech - - - - - -
-
-

CMPT 295: Unit - Data Representation

- -

Lecture 5

- -
    -
  • Representing fractional numbers in memory
  • -
  • IEEE floating point representation
  • -
- -

Last Lecture

-
    -
  • Demo of size and sign conversion in C: code and results posted!
  • -
  • Addition: -
      -
    • Unsigned/signed: -
        -
      • Behave the same way at the bit level
      • -
      • Interpretation of resulting bit vector (sum) may differ
      • -
      -
    • -
    • Unsigned addition -> true sum may overflow its w bits in memory (annotation with diagram of unisnged overflows, see lecture 04 to see full description of diagram) -
        -
      • If so, then actual sum = (x+y)mod2w(x + y) \mod 2^{w} (equivalent to subtracting 2w2^{w} from true sum (x+y)(x + y))
      • -
      -
    • -
    • Signed addition -> true sum may overflow its w bits in memory (annotation attached displaying diagram of negative and positive overflows, see Lecture 04 for detailed description of diagram) -
        -
      • If so then … -
          -
        • actual sum = U2Tw[(x+y)mod2w]\text{U2T}_{w}[(x + y) \mod 2^{w}]
        • -
        • true sum may be too +ve -> positive overflow OR too –ve -> negative overflow
        • -
        -
      • -
      -
    • -
    -
  • -
  • Subtraction -
      -
    • Becomes an addition where the 2nd operand is transformed into its additive inverse in two’s complement
    • -
    -
  • -
  • Multiplication: -
      -
    • Unsigned: actual product = (x×y)mod2w(x \times y) \mod 2^{w}
    • -
    • Signed: actual product = U2Tw[(x×y)mod2w]\text{U2T}_{w}[(x \times y) \mod 2^{w}]
    • -
    • Can be replaced by additions and shifts
    • -
    -
  • -
- -

Conclusion: the same bit pattern is interpreted differently.

- -

Questions

- -
    -
  • Why are we learning this?
  • -
  • What can we do in our program when we suspect that overflow may occur?
  • -
- -

Demo – Looking at integer additions in C

-
    -
  • What does the demo illustrate? -
      -
    • Unsigned addition -
        -
      • Without overflow
      • -
      • With overflow
      • -
      • Can overflow be predicted?
      • -
      -
    • -
    • Signed addition -
        -
      • Without overflow
      • -
      • With positive overflow and negative overflow
      • -
      • Can overflow be predicted?
      • -
      -
    • -
    -
  • -
  • This demo (code and results) posted on our course web site -4
  • -
- -

Today’s Menu

-
    -
  • (greyed out) Representing data in memory – Most of this is review -
      -
    • (greyed out) “Under the Hood” - Von Neumann architecture
    • -
    • (greyed out) Bits and bytes in memory -
        -
      • (greyed out) How to diagram memory -> Used in this course and other references
      • -
      • (greyed out) How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • (greyed out) What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • (greyed out) Order of bytes in memory -> Endian
      • -
      -
    • -
    • (greyed out) Bit manipulation – bitwise operations -
        -
      • (greyed out) Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • (greyed out) Representing integral numbers in memory -
      -
    • (greyed out) Unsigned and signed
    • -
    • (greyed out) Converting, expanding and truncating
    • -
    • (greyed out) Arithmetic operations
    • -
    -
  • -
  • (highlighted) Representing real numbers in memory
  • -
  • (highlighted) IEEE floating point representation
  • -
  • (greyed out) Floating point in C – casting, rounding, addition, …
  • -
- -

We’ll illustrate what we covered today by having a demo!

- -

Converting a fractional decimal number into a binary number (bit vector) [R2B(X)]

- -
    -
  • How would 346.625 (34658346 \frac{5}{8}) be represented as a binary number?
  • -
  • Expanding the subtraction method we have already seen:
  • -
- -

Starting number: 346.625

- -

Whole:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ValueAttempted Addition (subtraction) valueResultBinary ImplicationNote
346-256901×281 \times 2^{8}MSb
90-1280×270 \times 2^{7} 
90-64261×261 \times 2^{6} 
26-320×250 \times 2^{5} 
26-16101×241 \times 2^{4} 
10-821×231 \times 2^{3} 
2-40×220 \times 2^{2} 
2-201×211 \times 2^{1} 
0-10×210 \times 2^{1}LSb
- -

Fractional:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ValueAttempted addition (subtraction) valueresultbinary implicationnotes
.625-0.5.1251×211 \times 2^{-1}MSb
.125-0.250×220 \times 2^{-2} 
.125-0.12501×231 \times 2^{-3}LSb
- -

Binary representation is: 101011010.1012101011010.101_{2}

- -

First, last binary digit before the period are MSb, LSb respectively. -First, last binary digit after the period are also MSb, LSb respectively.

- -

Negative Powers of 2:

- -
    -
  • 212^{-1} = 0.5
  • -
  • 222^{−2} = 0.25
  • -
  • 232^{−3} = 0.125
  • -
  • 242^{−4} = 0.0625
  • -
  • 252^{−5} = 0.03125
  • -
- -

Converting a binary number into a fractional decimal number [R2B(X)]

- -
    -
  • How would 1011.10121011.101_{2} be represented as a fractional decimal number?
  • -
- -

Review: Fractional decimal numbers

- -

Positional notation:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NotationValue
did_{i}10i10^{i}
di1d_{i-1}10i110^{i-1}
d2d_{2}100
d1d_{1}10
d0d_{0}1
d1d_{-1}110\frac{1}{10}
d2d_{-2}1100\frac{1}{100}
d3d_{-3}11000\frac{1}{1000}
djd_{-j}10j10^{-j}
- -

Example: 2.345

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Digit in numberNote
210010^{0}
. 
310110^{-1}
410210^{-2}
510310^{-3}
- -

2.345=2×100+3×101+4×102+5×103 -2.345 = 2 \times 10^{0} + 3 \times 10^{−1} + 4 \times 10^{−2} + 5 \times 10^{−3} -

- -

Converting a binary number into a fractional decimal number [B2R(X)]

- -

Positional notation: can this be a possible encoding scheme?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bib_{i}2i2^{i}
bi1b_{i-1}2i12^{i-1}
b2b_{2}4
b1b_{1}2
b0b_{0}1
b1b_{-1}12\frac{1}{2}
b2b_{-2}14\frac{1}{4}
b3b_{-3}18\frac{1}{8}
bjb_{-j}2j2^{-j}
- -

Converting a binary number into a fractional decimal number [B2R(X)]

- -
    -
  • How would 1011.10121011.101_{2} be represented as a fractional decimal number?
  • -
  • Using the positional encoding scheme:
  • -
- -

1011.1012=(10112=1×23+1×21+1×20=1110)+(.1012=1×21+1×23=0.5+0.125=0.62510) -1011.101_{2} = \\ -(1011_{2} = 1 \times 2^{3} + 1 \times 2^{1} + 1 \times 2^{0} = 11_{10}) +\\ -(.101_{2} = 1 \times 2^{-1} + 1 \times 2^{-3} = 0.5 + 0.125 = 0.625_{10}) -

- -

Result: ____

- -

Negative Powers of 2

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212^{−1}0.5
222^{−2}0.25
232^{−3}0.125
242^{−4}0.0625
252^{−5}0.03125
262^{−6}0.015625
272^{−7}0.0078125
282^{−8}0.00390625
- -

Positional notation as encoding scheme?

- -
    -
  • One way to answer this question is to investigate whether the encoding scheme allows for arithmetic operations
  • -
  • Let’s see: Using the positional notation as an encoding scheme produces fractional binary numbers that can be -
      -
    • added
    • -
    • multiplied by 2 by shifting left
    • -
    • divided by 2 by shifting right (unsigned)
    • -
    -
  • -
- -

Example:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OperandBinaryFractionMakeup
 1011.10121011.101_{2}115811\frac{5}{8}8+2+1+12+188 + 2 + 1 + \frac{1}{2} + \frac{1}{8}
Divide by 2101.11012101.1101_{2}513165\frac{13}{16}4+1+12+14+1164 + 1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{16}
Divide by 210.11101210.11101_{2}229322\frac{29}{32}2+12+14+18+1322 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{32}
Multiply by 41011.10121011.101_{2}115811\frac{5}{8}8+2+1+12+188 + 2 + 1 + \frac{1}{2} + \frac{1}{8}
Multiply by 210111.01210111.01_{2}231423\frac{1}{4}16+4+2+1+1416 + 4 + 2 + 1 + \frac{1}{4}
- -

So far so good! 

- -

Positional notation as encoding scheme?

- -
    -
  • Advantage (so far): -
      -
    • Straightforward arithmetic: can shift to multiply and divide, convert
    • -
    -
  • -
  • Disadvantage: -
      -
    • Cannot encode all fractional numbers: -
        -
      • Can only represent numbers of the form x÷2kx \div 2^{k} (what about 15\frac{1}{5} or -34.8)
      • -
      -
    • -
    • Only one setting of binary point within the w bits -> this limits the range of possible values -
        -
      • What is this range? -
          -
        • Example: w = 32 bits and binary point located at 16th bit: -
            -
          • Whole number range: [0 … 65535]
          • -
          • Fraction range: [0 … 1 - ε]
          • -
          • - 1bits=ϵ1 - \text{bits} = \epsilon -
          • -
          • Range: [0.0 … 65535.99998]
          • -
          -
        • -
        -
      • -
      -
    • -
    -
  • -
- -

Not so good anymore!

- -

Representing fractional numbers in memory

- -
    -
  • Here is another possible encoding scheme: IEEE floating point representation (IEEE Standard 754)
  • -
  • Overview: -
      -
    • Binary Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E} -
        -
      • s – Sign bit -> determines whether number is negative or positive
      • -
      • M – Significand (or Mantissa) -> fractional part of number
      • -
      • E – Exponent
      • -
      -
    • -
    -
  • -
  • Form of bit pattern (number of items not important, focus on scale): [s|eee|fffffffffffff] -
      -
    • Most significant bit (MSb) s (similar to sign-magnitude encoding)
    • -
    • exp (e) field encodes E (but is not equal to E)
    • -
    • frac (f) field encodes M (but is not equal to M)
    • -
    -
  • -
- -

IEEE Floating Point Representation – Precision options

- -
    -
  • Single precision: 32 bits ≈ 7 decimal digits, range:10±38 (in C: float) -
      -
    • In C: diagram of memory showing: -
        -
      • 1 sign bit
      • -
      • 8 exp bits
      • -
      • 23 frac bits
      • -
      -
    • -
    -
  • -
  • Double precision: 64 bits ≈ 16 decimal digits, range:10±308 (in C: double) -
      -
    • In C: diagram of memory showing: -
        -
      • 1 sign bit
      • -
      • 11 exp bits
      • -
      • 52 frac bits
      • -
      -
    • -
    -
  • -
- -

IEEE Floating Point Representation – Three “kinds” of values

- -

Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E}

- -
    -
  • 1 sign bit
  • -
  • k exp bits -
      -
    • denormalized: 00…00 (all 0’s)
    • -
    • normalized: exp != 0 and exp != 11..11
    • -
    • special cases: 11…11 (all 1’s)
    • -
    -
  • -
  • -

    n frac bits

    -
  • -
  • E = exp - bias, bias = 2k112^{k-1} -1
  • -
  • M = 1 + frac
  • -
- -

Why is E biased? Using single precision as an example:

- -
    -
  • exp range: [00000001 .. 11111110] and bias = 28112^{8-1} – 1
  • -
  • E range: [-126 .. 127]
  • -
  • If no bias: E range: [1 .. 254] => 212^{1} to 22542^{254}
  • -
- -

Why adding 1 to frac? Because number V is first normalized before it is converted.

- -

Review: Scientific Notation and normalization

- -
    -
  • From Wikipedia: -
      -
    • Scientific notation is a way of expressing numbers that are too large or too small (usually would result a long string of digits) to be conveniently written in decimal form.
    • -
    • In scientific notation, nonzero numbers are written in the form
    • -
    • In normalized notation, the exponent n is chosen so that the absolute value of the significand m is at least 1 but less than 10.
    • -
    -
  • -
  • Examples: -
      -
    • A proton’s mass is 0.0000000000000000000000000016726 kg -> 1.6726×10271.6726 \times 10^{−27}kg
    • -
    • Speed of light is 299,792,458 m/s -> 2.99792,458×1082.99792,458 \times 10^{8} m/s
    • -
    -
  • -
- -

Syntax:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NotationName
+/−sign
d0d_{0}, d1d_{-1}, d2d_{-2}, d3d_{-3}dnd_{-n}significand
×times
bbase
exp^{exp}exponent
- -

Let’s try: 101011010.1012101011010.101_{2} = ____

- -

Summary

- -
    -
  • Representing integral numbers (signed/unsigned) in memory: -
      -
    • Encode schemes allow for small range of values exactly
    • -
    -
  • -
  • Representing fractional numbers in memory: -
      -
    1. Positional notation (advantages and disadvantages)
    2. -
    3. IEEE floating point representation: wider range, mostly approximately
    4. -
    -
  • -
  • Overview of IEEE Floating Point representation
  • -
  • - V=(1)s×M×2EV = (-1)^{s} \times M \times 2^{E} -
  • -
  • Precision options
  • -
  • 3 kinds: normalized, denormalized and special values
  • -
- -

Today’s Menu

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -18 -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -
-
-
-
- - diff --git a/_site/melody/cmpt-295/06/06.html b/_site/melody/cmpt-295/06/06.html deleted file mode 100644 index 710fbfe..0000000 --- a/_site/melody/cmpt-295/06/06.html +++ /dev/null @@ -1,596 +0,0 @@ - - - - - | tait.tech - - - - - -
-
-

CMPT 295

- -
    -
  • Unit - Data Representation -
      -
    • Lecture 6 – Representing fractional numbers in memory
    • -
    • IEEE floating point representation – cont’d
    • -
    -
  • -
- -

Have you heard of that new band “1023 Megabytes”?

- -

They’re pretty good, -but they don’t have a gig just yet. -😭

- -

Last Lecture

- -
    -
  • Representing integral numbers in memory -
      -
    • Can encode a small range of values exactly (in 1, 2, 4, 8 bytes) -
        -
      • For example: We can represent the values -128 to 127 exactly in 1 byte using a signed char in C
      • -
      -
    • -
    -
  • -
  • Representing fractional numbers in memory -
      -
    1. Positional notation has some advantages, but also disadvantages -> so not used!
    2. -
    3. IEEE floating point representation: can encode a much larger range of e.g., single precision: [10-38..1038] values approximately (in 4 or 8 bytes)
    4. -
    -
  • -
  • Overview of IEEE floating point representation -
      -
    • Precision options (float 32-bit, double 64-bit)
    • -
    • V = (-1)s x M x 2E
    • -
    • s –> sign bit
    • -
    • exp encodes E (but != E)
    • -
    • frac encodes M (but != M)
    • -
    -
  • -
- -

We interpret the bit vector (expressed in IEEE floating point encoding) stored in memory using this equation.

- -

Today’s Menu

- -
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -4 -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -

IEEE Floating Point Representation Three “kinds” of values

- -

We interpret the bit vector -(expressed in IEEE floating point encoding) stored in memory using this equation:

- -

V=(1)sM2E -V = (-1)^{s} M 2^{E} -

- -

Bit breakdown–exp and frac interpreted as unsigned:

- -
    -
  • s = 1 bit
  • -
  • exp = k bits -
      -
    1. If exp != 0 and exp != 11…11 (exp range: [0000001…11111110]). Equations: -
        -
      • E=expbiasE = \text{exp} - \text{bias} and bias=2k11\text{bias} = 2^{k-1} - 1
      • -
      • - M=1+fracM = 1 + \text{frac} -
      • -
      -
    2. -
    3. If exp = 00…00 (all 0’s) => denormalized. Equations: -
        -
      • E=1biasE = 1 - \text{bias} and bias=2k11\text{bias} = 2^{k-1} - 1
      • -
      • - M=fracM = \text{frac} -
      • -
      -
    4. -
    5. If exp 11…11 (all 1’s) => special cases. -
        -
      • Case 1: frac = 000…0
      • -
      • Case 2: frac != 000…0
      • -
      -
    6. -
    -
  • -
- -

IEEE floating point representation - normalized

- -

Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E}

- -

Bit breakdown:

- -
    -
  • s = 1 bit
  • -
  • exp = k bits -
      -
    • If exp != 0 and exp != 11…11 (exp range: [00000001…11111110]) => normalized. Equations: -
        -
      • E=expbiasE = \text{exp} - \text{bias} and bias=2k11\text{bias} = 2^{k-1} - 1
      • -
      • - M=1+fracM = 1 + \text{frac} -
      • -
      -
    • -
    -
  • -
- -

Why is E biased?

- -

Using single precision as an example (s = 1 bit, exp = 8 bits, frac = 23 bits):

- -
    -
  • (exp range: [00000001 .. 11111110]) => [110...25410][1_{10}...254_{10}]
  • -
  • If E is not biased (i.e. E = exp), then E range [110...25410][1_{10} ... 254_{10}]
  • -
  • V range [212^{1}22542^{254}] = [2…2.89×1076\approx 2.89 \times 10^{76}] (so cannot express numbers < 2)
  • -
  • By biasing E (i.e. E = exp - bias), then E range: [1-127…254-127] == [-126…127] (since k = 8, bias = 28112^{8-1} - 1 = 127)
  • -
  • V range: [21262^{-126}21272^{127}] = [1.18×1038\approx 1.18 \times 10^{-38}1.7×1038\approx 1.7 \times 10^{38} (so can now express very small (and very large) numbers)
  • -
  • Why adding 1 to frac? Because the number (or value) V is first normalized before it is converted.
  • -
- -

Review: Scientific Notation and normalization

- -
    -
  • From Wikipedia: -
      -
    • Scientific notation is a way of expressing numbers that are too large or too small to be conveniently written in decimal form (as they are long strings of digits).
    • -
    • In scientific notation, nonzero numbers are written in the form +/- M × 10n
    • -
    • In normalized notation, the exponent n is chosen such that the absolute value of the significand M is at least 1 (M = 1.0) but less than the base -
        -
      • M range for base 10 => [1.0 .. 10.0 – ε ]
      • -
      • M range for base 2 => [1.0 .. 2.0 – ε ]
      • -
      -
    • -
    -
  • -
  • -

    Examples:

    - -
      -
    • A proton’s mass is 0.0000000000000000000000000016726 kg -> 1.6726×10271.6726 \times 10^{−27} kg
    • -
    • Speed of light is 299,792,458 m/s -> 2.99792,458×1082.99792,458 \times 10^{8} m/s
    • -
    -
  • -
- -

Syntax of normalized notation:

- - - - - - - - - - - - - - - - - - - - - - - - - - -
NameNotation
Sign+/-
Significantd0,d1,d2,d3d_{0}, d_{-1}, d_{-2}, d_{-3}dnd_{-n}
Baseb
Exponentexp^{\text{exp}}
- -
    -
  • Let’s try: 101011010.1012101011010.101_{2} -> ___
  • -
- -

Let’s try normalizing these fractional binary numbers!

- -
    -
  1. - 101011010.1012101011010.101_{2} -
  2. -
  3. - 0.00000000110120.000000001101_{2} -
  4. -
  5. - 11000000111001211000000111001_{2} -
  6. -
- -

IEEE floating point representation

- -
    -
  • Once V is normalized, we apply the equations -
      -
    • - V=(1)sM2E=1.010110101012×28V = (–1)^{s} M 2^{E} = 1.01011010101_{2} \times 2^{8} -
    • -
    • s = ???
    • -
    • E=expbiasE = \text{exp} - \text{bias} where bias=2k11=271=1281=127\text{bias} = 2^{k-1} - 1 = 2^{7} - 1 = 128 - 1 = 127
    • -
    • exp = E + bias = ___
    • -
    • M = 1 + frac = ___
    • -
    • s = 1 bit, exp = k bits => 8 bits, frac n bits => 23 bits
    • -
    • bit vector in memory:
    • -
    -
  • -
- -

Why adding 1 to frac (or subtracting 1 from M)?

- -
    -
  • Because the number (or value) V is first normalized before it is converted. -
      -
    • As part of this normalization process, we transform our binary number such that its significand M is within the range [1.0 .. 2.0 – ε ]
    • -
    • Remember: M range for base 2 => [1.0 … 2.0 – ε]
    • -
    • This implies that M is always at least 1.0, so its integral part always has the value 1
    • -
    • So since this bit is always part of M, IEEE 754 does not explicitly save it in its bit pattern (i.e., in memory)
    • -
    • Instead, this bit is implied!
    • -
    -
  • -
- -

Why adding 1 to frac (or subtracting 1 from M)?

- -

Implying this bit has the following effects:

- -

We get the -leading bit -for free!

- -
    -
  1. We save 1 bit when we convert (represent) a fractional decimal number into a bit pattern using IEEE 754 floating point representation
  2. -
  3. We have to add this 1 bit back when we convert from a bit pattern (IEEE 754 floating point representation) back to a fractional decimal
  4. -
- -

Example: V=(1)sM2E=1.01011010101×28V = (–1)^{s} M 2^{E} = 1.01011010101 \times 2^{8}

- -

M = 1. 01011010101 => M = 1 + frac

- -

This bit is implied hence not stored in the bit pattern produced -by the IEEE 754 floating point representation, and what we -store in the frac part of the IEEE 754 bit pattern is 01011010101

- -

IEEE floating point representation (single precision)

- -
    -
  • What if the 4 bytes starting at M[0x0000] represented a fractional -decimal number (encoded as an IEEE floating point number) -> value? -single precision
  • -
- -

Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E}

- - - - - - - - - - - - - - - - - - - - - - -
ValueNotes
1 
10000111k=8 bits, interpreted as unsigned
01011010101000000000000n=23 bits, interpreted as unsigned
- -
    -
  • exp ≠ 0 and exp ≠ 111111112 -> normalized
  • -
  • s = ___
  • -
  • E = exp – bias where bias = 2k11=271=1281=1272^{k-1} – 1 = 2^{7} – 1 = 128 – 1 = 127$
  • -
  • E = ____ - 127 =
  • -
  • M = 1 + frac = 1 + ___
  • -
  • V = ____
  • -
- -

Little endian memory layout:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size-1 
0x000311000011
0x000210101101
0x000101010000
0x000000000000
- -

Let’s give it a go!

- -
    -
  • What if the 4 bytes starting at M[0x0000] represented a fractional -decimal number (encoded as an IEEE floating point number) -> value?
  • -
- -

Numerical form: V=(1)sM2EV = (-1)^{s} M 2^{E}

- -

single precision

- - - - - - - - - - - - - - - - - - - - - - -
ValueNotes
0 
10001100k=8 bits, interpreted as unsigned
11011011011000000000000n=23 bits, interpreted as unsigned
- -
    -
  • exp ≠ 0 and exp ≠ 111111112 -> normalized
  • -
  • s = ____
  • -
  • E = exp - bias where bias=271=1281=127\text{bias} = 2^{7} - 1 = 128 - 1 = 127
  • -
  • E = ____ - 127 = ___
  • -
  • M = 1 + frac = 1 + ____
  • -
  • V = ____
  • -
- -

Little endian memory map:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size-1 
0x000301000110
0x000201101101
0x000110110000
0x000000000000
- -

IEEE floating point representation (single precision)

- -

How would 47.21875 be encoded as IEEE floating point number?

- -
    -
  1. Convert 47.28 to binary (using the positional notation R2B(X)) => -
      -
    • - 47=101111247 = 101111_{2} -
    • -
    • - .21875=.001112.21875 = .00111_{2} -
    • -
    -
  2. -
  3. Normalize binary number: -101111.00111 => 1.01111001112×251.0111100111_{2} \times 2^{5} -
      -
    • - V=(1)sM2EV = (–1)^{s} M 2^{E} -
    • -
    -
  4. -
  5. Determine … -
      -
    • s = 0
    • -
    • E = exp – bias where bias=2k11=271=1281=127\text{bias} = 2^{k-1} – 1 = 2^{7} – 1 = 128 – 1 = 127
    • -
    • exp = E + bias = 5 + 127 = 132 => U2B(132) => 10000100
    • -
    • M = 1 + frac -> frac = M - 1 => 1.011110011121=.011110011121.0111100111_{2} - 1 = .0111100111_{2}
    • -
    -
  6. -
  7. 32 bits organized in s|exp|frac: [0|10000100|01111001110000000000000}
  8. -
  9. 0x423CE000
  10. -
- -

IEEE floating point representation (single precision)

- -

How would 12345.75 be encoded as IEEE floating point number?

- -

V=(1)sM2E -V = (-1)^{s} M 2^{E} -

- -
    -
  1. Convert 12345.75 to binary -
      -
    • 12345 => ____ .75 => ____
    • -
    -
  2. -
  3. Normalize binary number:
  4. -
  5. Determine … -
      -
    • s = ____
    • -
    • E = exp – bias where bias=2k11=271=1281=127\text{bias} = 2^{k-1} – 1 = 2^{7} – 1 = 128 – 1 = 127
    • -
    • exp = E + bias = ____
    • -
    • M = 1 + frac -> frac = M - 1
    • -
    -
  6. -
  7. [_|________|_______________________]
  8. -
  9. Express in hex:
  10. -
- -

Summary

- -
    -
  • IEEE Floating Point Representation -
      -
    1. Denormalized
    2. -
    3. Special cases
    4. -
    5. Normalized => exp ≠ 000…0 and exp ≠ 111…1 -
        -
      • Single precision: bias = 127, exp: [1..254], E: [-126..127] => [10-38 … 1038]
      • -
      • Called “normalized” because binary numbers are normalized
      • -
      -
        -
      • Effect: “We get the leading bit for free” -
          -
        • Leading bit is always assumed (never part of bit pattern)
        • -
        -
      • -
      -
    6. -
    -
  • -
  • IEEE floating point number as encoding scheme -
      -
    • Fractional decimal number  IEEE 754 (bit pattern)
    • -
    • - V=(1)sM2EV = (–1)^{s} M 2^{E} -
        -
      • s is sign bit, M = 1 + frac, E = exp – bias, bias=2k11\text{bias} = 2^{k-1} – 1 and k is width of exp
      • -
      -
    • -
    -
  • -
- -

Next Lecture

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- - -
-
-
-
- - diff --git a/_site/melody/cmpt-295/06/06/index.html b/_site/melody/cmpt-295/06/06/index.html deleted file mode 100644 index 710fbfe..0000000 --- a/_site/melody/cmpt-295/06/06/index.html +++ /dev/null @@ -1,596 +0,0 @@ - - - - - | tait.tech - - - - - -
-
-

CMPT 295

- -
    -
  • Unit - Data Representation -
      -
    • Lecture 6 – Representing fractional numbers in memory
    • -
    • IEEE floating point representation – cont’d
    • -
    -
  • -
- -

Have you heard of that new band “1023 Megabytes”?

- -

They’re pretty good, -but they don’t have a gig just yet. -😭

- -

Last Lecture

- -
    -
  • Representing integral numbers in memory -
      -
    • Can encode a small range of values exactly (in 1, 2, 4, 8 bytes) -
        -
      • For example: We can represent the values -128 to 127 exactly in 1 byte using a signed char in C
      • -
      -
    • -
    -
  • -
  • Representing fractional numbers in memory -
      -
    1. Positional notation has some advantages, but also disadvantages -> so not used!
    2. -
    3. IEEE floating point representation: can encode a much larger range of e.g., single precision: [10-38..1038] values approximately (in 4 or 8 bytes)
    4. -
    -
  • -
  • Overview of IEEE floating point representation -
      -
    • Precision options (float 32-bit, double 64-bit)
    • -
    • V = (-1)s x M x 2E
    • -
    • s –> sign bit
    • -
    • exp encodes E (but != E)
    • -
    • frac encodes M (but != M)
    • -
    -
  • -
- -

We interpret the bit vector (expressed in IEEE floating point encoding) stored in memory using this equation.

- -

Today’s Menu

- -
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -4 -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- -

IEEE Floating Point Representation Three “kinds” of values

- -

We interpret the bit vector -(expressed in IEEE floating point encoding) stored in memory using this equation:

- -

V=(1)sM2E -V = (-1)^{s} M 2^{E} -

- -

Bit breakdown–exp and frac interpreted as unsigned:

- -
    -
  • s = 1 bit
  • -
  • exp = k bits -
      -
    1. If exp != 0 and exp != 11…11 (exp range: [0000001…11111110]). Equations: -
        -
      • E=expbiasE = \text{exp} - \text{bias} and bias=2k11\text{bias} = 2^{k-1} - 1
      • -
      • - M=1+fracM = 1 + \text{frac} -
      • -
      -
    2. -
    3. If exp = 00…00 (all 0’s) => denormalized. Equations: -
        -
      • E=1biasE = 1 - \text{bias} and bias=2k11\text{bias} = 2^{k-1} - 1
      • -
      • - M=fracM = \text{frac} -
      • -
      -
    4. -
    5. If exp 11…11 (all 1’s) => special cases. -
        -
      • Case 1: frac = 000…0
      • -
      • Case 2: frac != 000…0
      • -
      -
    6. -
    -
  • -
- -

IEEE floating point representation - normalized

- -

Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E}

- -

Bit breakdown:

- -
    -
  • s = 1 bit
  • -
  • exp = k bits -
      -
    • If exp != 0 and exp != 11…11 (exp range: [00000001…11111110]) => normalized. Equations: -
        -
      • E=expbiasE = \text{exp} - \text{bias} and bias=2k11\text{bias} = 2^{k-1} - 1
      • -
      • - M=1+fracM = 1 + \text{frac} -
      • -
      -
    • -
    -
  • -
- -

Why is E biased?

- -

Using single precision as an example (s = 1 bit, exp = 8 bits, frac = 23 bits):

- -
    -
  • (exp range: [00000001 .. 11111110]) => [110...25410][1_{10}...254_{10}]
  • -
  • If E is not biased (i.e. E = exp), then E range [110...25410][1_{10} ... 254_{10}]
  • -
  • V range [212^{1}22542^{254}] = [2…2.89×1076\approx 2.89 \times 10^{76}] (so cannot express numbers < 2)
  • -
  • By biasing E (i.e. E = exp - bias), then E range: [1-127…254-127] == [-126…127] (since k = 8, bias = 28112^{8-1} - 1 = 127)
  • -
  • V range: [21262^{-126}21272^{127}] = [1.18×1038\approx 1.18 \times 10^{-38}1.7×1038\approx 1.7 \times 10^{38} (so can now express very small (and very large) numbers)
  • -
  • Why adding 1 to frac? Because the number (or value) V is first normalized before it is converted.
  • -
- -

Review: Scientific Notation and normalization

- -
    -
  • From Wikipedia: -
      -
    • Scientific notation is a way of expressing numbers that are too large or too small to be conveniently written in decimal form (as they are long strings of digits).
    • -
    • In scientific notation, nonzero numbers are written in the form +/- M × 10n
    • -
    • In normalized notation, the exponent n is chosen such that the absolute value of the significand M is at least 1 (M = 1.0) but less than the base -
        -
      • M range for base 10 => [1.0 .. 10.0 – ε ]
      • -
      • M range for base 2 => [1.0 .. 2.0 – ε ]
      • -
      -
    • -
    -
  • -
  • -

    Examples:

    - -
      -
    • A proton’s mass is 0.0000000000000000000000000016726 kg -> 1.6726×10271.6726 \times 10^{−27} kg
    • -
    • Speed of light is 299,792,458 m/s -> 2.99792,458×1082.99792,458 \times 10^{8} m/s
    • -
    -
  • -
- -

Syntax of normalized notation:

- - - - - - - - - - - - - - - - - - - - - - - - - - -
NameNotation
Sign+/-
Significantd0,d1,d2,d3d_{0}, d_{-1}, d_{-2}, d_{-3}dnd_{-n}
Baseb
Exponentexp^{\text{exp}}
- -
    -
  • Let’s try: 101011010.1012101011010.101_{2} -> ___
  • -
- -

Let’s try normalizing these fractional binary numbers!

- -
    -
  1. - 101011010.1012101011010.101_{2} -
  2. -
  3. - 0.00000000110120.000000001101_{2} -
  4. -
  5. - 11000000111001211000000111001_{2} -
  6. -
- -

IEEE floating point representation

- -
    -
  • Once V is normalized, we apply the equations -
      -
    • - V=(1)sM2E=1.010110101012×28V = (–1)^{s} M 2^{E} = 1.01011010101_{2} \times 2^{8} -
    • -
    • s = ???
    • -
    • E=expbiasE = \text{exp} - \text{bias} where bias=2k11=271=1281=127\text{bias} = 2^{k-1} - 1 = 2^{7} - 1 = 128 - 1 = 127
    • -
    • exp = E + bias = ___
    • -
    • M = 1 + frac = ___
    • -
    • s = 1 bit, exp = k bits => 8 bits, frac n bits => 23 bits
    • -
    • bit vector in memory:
    • -
    -
  • -
- -

Why adding 1 to frac (or subtracting 1 from M)?

- -
    -
  • Because the number (or value) V is first normalized before it is converted. -
      -
    • As part of this normalization process, we transform our binary number such that its significand M is within the range [1.0 .. 2.0 – ε ]
    • -
    • Remember: M range for base 2 => [1.0 … 2.0 – ε]
    • -
    • This implies that M is always at least 1.0, so its integral part always has the value 1
    • -
    • So since this bit is always part of M, IEEE 754 does not explicitly save it in its bit pattern (i.e., in memory)
    • -
    • Instead, this bit is implied!
    • -
    -
  • -
- -

Why adding 1 to frac (or subtracting 1 from M)?

- -

Implying this bit has the following effects:

- -

We get the -leading bit -for free!

- -
    -
  1. We save 1 bit when we convert (represent) a fractional decimal number into a bit pattern using IEEE 754 floating point representation
  2. -
  3. We have to add this 1 bit back when we convert from a bit pattern (IEEE 754 floating point representation) back to a fractional decimal
  4. -
- -

Example: V=(1)sM2E=1.01011010101×28V = (–1)^{s} M 2^{E} = 1.01011010101 \times 2^{8}

- -

M = 1. 01011010101 => M = 1 + frac

- -

This bit is implied hence not stored in the bit pattern produced -by the IEEE 754 floating point representation, and what we -store in the frac part of the IEEE 754 bit pattern is 01011010101

- -

IEEE floating point representation (single precision)

- -
    -
  • What if the 4 bytes starting at M[0x0000] represented a fractional -decimal number (encoded as an IEEE floating point number) -> value? -single precision
  • -
- -

Numerical Form: V=(1)sM2EV = (–1)^{s} M 2^{E}

- - - - - - - - - - - - - - - - - - - - - - -
ValueNotes
1 
10000111k=8 bits, interpreted as unsigned
01011010101000000000000n=23 bits, interpreted as unsigned
- -
    -
  • exp ≠ 0 and exp ≠ 111111112 -> normalized
  • -
  • s = ___
  • -
  • E = exp – bias where bias = 2k11=271=1281=1272^{k-1} – 1 = 2^{7} – 1 = 128 – 1 = 127$
  • -
  • E = ____ - 127 =
  • -
  • M = 1 + frac = 1 + ___
  • -
  • V = ____
  • -
- -

Little endian memory layout:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size-1 
0x000311000011
0x000210101101
0x000101010000
0x000000000000
- -

Let’s give it a go!

- -
    -
  • What if the 4 bytes starting at M[0x0000] represented a fractional -decimal number (encoded as an IEEE floating point number) -> value?
  • -
- -

Numerical form: V=(1)sM2EV = (-1)^{s} M 2^{E}

- -

single precision

- - - - - - - - - - - - - - - - - - - - - - -
ValueNotes
0 
10001100k=8 bits, interpreted as unsigned
11011011011000000000000n=23 bits, interpreted as unsigned
- -
    -
  • exp ≠ 0 and exp ≠ 111111112 -> normalized
  • -
  • s = ____
  • -
  • E = exp - bias where bias=271=1281=127\text{bias} = 2^{7} - 1 = 128 - 1 = 127
  • -
  • E = ____ - 127 = ___
  • -
  • M = 1 + frac = 1 + ____
  • -
  • V = ____
  • -
- -

Little endian memory map:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddressM[]
size-1 
0x000301000110
0x000201101101
0x000110110000
0x000000000000
- -

IEEE floating point representation (single precision)

- -

How would 47.21875 be encoded as IEEE floating point number?

- -
    -
  1. Convert 47.28 to binary (using the positional notation R2B(X)) => -
      -
    • - 47=101111247 = 101111_{2} -
    • -
    • - .21875=.001112.21875 = .00111_{2} -
    • -
    -
  2. -
  3. Normalize binary number: -101111.00111 => 1.01111001112×251.0111100111_{2} \times 2^{5} -
      -
    • - V=(1)sM2EV = (–1)^{s} M 2^{E} -
    • -
    -
  4. -
  5. Determine … -
      -
    • s = 0
    • -
    • E = exp – bias where bias=2k11=271=1281=127\text{bias} = 2^{k-1} – 1 = 2^{7} – 1 = 128 – 1 = 127
    • -
    • exp = E + bias = 5 + 127 = 132 => U2B(132) => 10000100
    • -
    • M = 1 + frac -> frac = M - 1 => 1.011110011121=.011110011121.0111100111_{2} - 1 = .0111100111_{2}
    • -
    -
  6. -
  7. 32 bits organized in s|exp|frac: [0|10000100|01111001110000000000000}
  8. -
  9. 0x423CE000
  10. -
- -

IEEE floating point representation (single precision)

- -

How would 12345.75 be encoded as IEEE floating point number?

- -

V=(1)sM2E -V = (-1)^{s} M 2^{E} -

- -
    -
  1. Convert 12345.75 to binary -
      -
    • 12345 => ____ .75 => ____
    • -
    -
  2. -
  3. Normalize binary number:
  4. -
  5. Determine … -
      -
    • s = ____
    • -
    • E = exp – bias where bias=2k11=271=1281=127\text{bias} = 2^{k-1} – 1 = 2^{7} – 1 = 128 – 1 = 127
    • -
    • exp = E + bias = ____
    • -
    • M = 1 + frac -> frac = M - 1
    • -
    -
  6. -
  7. [_|________|_______________________]
  8. -
  9. Express in hex:
  10. -
- -

Summary

- -
    -
  • IEEE Floating Point Representation -
      -
    1. Denormalized
    2. -
    3. Special cases
    4. -
    5. Normalized => exp ≠ 000…0 and exp ≠ 111…1 -
        -
      • Single precision: bias = 127, exp: [1..254], E: [-126..127] => [10-38 … 1038]
      • -
      • Called “normalized” because binary numbers are normalized
      • -
      -
        -
      • Effect: “We get the leading bit for free” -
          -
        • Leading bit is always assumed (never part of bit pattern)
        • -
        -
      • -
      -
    6. -
    -
  • -
  • IEEE floating point number as encoding scheme -
      -
    • Fractional decimal number  IEEE 754 (bit pattern)
    • -
    • - V=(1)sM2EV = (–1)^{s} M 2^{E} -
        -
      • s is sign bit, M = 1 + frac, E = exp – bias, bias=2k11\text{bias} = 2^{k-1} – 1 and k is width of exp
      • -
      -
    • -
    -
  • -
- -

Next Lecture

-
    -
  • Representing data in memory – Most of this is review -
      -
    • “Under the Hood” - Von Neumann architecture
    • -
    • Bits and bytes in memory -
        -
      • How to diagram memory -> Used in this course and other references
      • -
      • How to represent series of bits -> In binary, in hexadecimal (conversion)
      • -
      • What kind of information (data) do series of bits represent -> Encoding scheme
      • -
      • Order of bytes in memory -> Endian
      • -
      -
    • -
    • Bit manipulation – bitwise operations -
        -
      • Boolean algebra + Shifting
      • -
      -
    • -
    -
  • -
  • Representing integral numbers in memory -
      -
    • Unsigned and signed
    • -
    • Converting, expanding and truncating
    • -
    • Arithmetic operations
    • -
    -
  • -
  • Representing real numbers in memory -
      -
    • IEEE floating point representation
    • -
    • Floating point in C – casting, rounding, addition, …
    • -
    -
  • -
- - -
-
-
-
- - diff --git a/_site/melody/cmpt-295/06/Lecture_06_Data_Representation_Fractional_Numbers.pdf b/_site/melody/cmpt-295/06/Lecture_06_Data_Representation_Fractional_Numbers.pdf deleted file mode 100644 index a1c8ac4..0000000 Binary files a/_site/melody/cmpt-295/06/Lecture_06_Data_Representation_Fractional_Numbers.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/cmpt205-06.zip b/_site/melody/cmpt-295/cmpt205-06.zip deleted file mode 100644 index 04257b7..0000000 Binary files a/_site/melody/cmpt-295/cmpt205-06.zip and /dev/null differ diff --git a/_site/melody/cmpt-295/cmpt295-05.zip b/_site/melody/cmpt-295/cmpt295-05.zip deleted file mode 100644 index 9d338f7..0000000 Binary files a/_site/melody/cmpt-295/cmpt295-05.zip and /dev/null differ diff --git a/_site/melody/cmpt-295/computer-bus/Computer_Bus.pdf b/_site/melody/cmpt-295/computer-bus/Computer_Bus.pdf deleted file mode 100644 index 67d0497..0000000 Binary files a/_site/melody/cmpt-295/computer-bus/Computer_Bus.pdf and /dev/null differ diff --git a/_site/melody/cmpt-295/computer-bus/Computer_Bus.pdf.txt b/_site/melody/cmpt-295/computer-bus/Computer_Bus.pdf.txt deleted file mode 100644 index 1f53a6d..0000000 --- a/_site/melody/cmpt-295/computer-bus/Computer_Bus.pdf.txt +++ /dev/null @@ -1,4 +0,0 @@ -Computer Bus -Two images side by side, -Left image of a ribbon cable, -right image of a specialty device with many ribbon cables attached to it. diff --git a/_site/melody/cmpt-295/03/03/index.html b/_site/melody/cmpt/03/index.html similarity index 100% rename from _site/melody/cmpt-295/03/03/index.html rename to _site/melody/cmpt/03/index.html diff --git a/_site/melody/cmpt-295/04/04.html b/_site/melody/cmpt/04/index.html similarity index 100% rename from _site/melody/cmpt-295/04/04.html rename to _site/melody/cmpt/04/index.html diff --git a/_site/melody/cmpt-295/01/01/index.html b/_site/melody/cmpt/test1/index.html similarity index 100% rename from _site/melody/cmpt-295/01/01/index.html rename to _site/melody/cmpt/test1/index.html diff --git a/_site/sitemap.xml b/_site/sitemap.xml index 7b0fe92..6a99171 100644 --- a/_site/sitemap.xml +++ b/_site/sitemap.xml @@ -2,31 +2,31 @@ /emacspeak-tutorials/arrays/ -2021-09-22T08:19:13-06:00 +2021-09-22T11:33:06-06:00 /emacspeak-tutorials/functions/ -2021-09-22T08:19:13-06:00 +2021-09-22T11:33:06-06:00 /emacspeak-tutorials/loops/ -2021-09-22T08:19:13-06:00 +2021-09-22T11:33:06-06:00 /emacspeak-tutorials/pointers/ -2021-09-22T08:19:13-06:00 +2021-09-22T11:33:06-06:00 /emacspeak-tutorials/printing/ -2021-09-22T08:19:13-06:00 +2021-09-22T11:33:06-06:00 /emacspeak-tutorials/structs/ -2021-09-22T08:19:13-06:00 +2021-09-22T11:33:06-06:00 /emacspeak-tutorials/user-input/ -2021-09-22T08:19:13-06:00 +2021-09-22T11:33:06-06:00 /2020/01/22/padding-and-margin/ @@ -153,31 +153,16 @@ 2021-09-18T00:00:00-06:00 -/melody/cmpt-225/01/01-intro/ +/melody/225/01-intro/ -/melody/cmpt-295/01/01/ +/melody/225/02-stacks-and-queues/ -/melody/cmpt-225/02/02-stacks-and-queues/ +/melody/cmpt/03/ -/melody/cmpt-225/03/03-memory-and-pointers/ - - -/melody/cmpt-295/03/03/ - - -/melody/cmpt-295/04/04/ - - -/melody/cmpt-295/06/06/ - - -/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated/ - - -/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers/ +/melody/cmpt/04/ /blog/ @@ -186,10 +171,10 @@ / -/ideas/ +/contact/ -/links/ +/scholarships/2020/cnib/ /cover-letters/protonmail/ @@ -198,22 +183,22 @@ /cover-letters/bloombase/ -/cover-letter-vcc/ +/about/ -/scholarships/2020/cnib/ +/cover-letter-vcc/ -/emacspeak-tutorials/ +/links/ -/contact/ +/ideas/ /resume/ -/about/ +/emacspeak-tutorials/ /tutoring/ @@ -222,83 +207,10 @@ /tests/latex-grouping/ -/assets/pdf/bios-accessibility.pdf -2021-06-10T17:37:52-06:00 - - -/melody/cmpt-225/01/01-intro.html -2021-09-20T18:14:12-06:00 - - -/melody/cmpt-225/02/02-stacks-and-queues.html -2021-09-20T18:14:12-06:00 - - -/melody/cmpt-225/03/03-memory-and-pointers.html -2021-09-20T18:14:12-06:00 +/melody/cmpt/test1/ -/melody/cmpt-295/01/Lecture_01_Activity_Code.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/01/Lecture_01_Course_Overview.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/01/Lecture_01_Course_Overview_Annotated.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/01/Lecture_01_Course_Overview_annotated.html -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.html -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/02/Lecture_02_Data_Representation_Intro_Annotated.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/03/03.html -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/03/Lecture_03_Data_Representation_Integers.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/04/04.html -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/04/Lecture_04_Data_Representation_Integers.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.html -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/05/Lecture_05_Data_Representation_Fractional_Numbers.pdf -2021-09-20T18:14:13-06:00 - - -/melody/cmpt-295/06/06.html -2021-09-20T20:30:42-06:00 - - -/melody/cmpt-295/06/Lecture_06_Data_Representation_Fractional_Numbers.pdf -2021-09-20T18:23:01-06:00 - - -/melody/cmpt-295/computer-bus/Computer_Bus.pdf -2021-09-20T18:14:13-06:00 +/assets/pdf/bios-accessibility.pdf +2021-09-22T11:25:57-06:00