Clear bit shifting. Add notes on floor/ceiling functions.
parent
30c6fb97b5
commit
5fdd0b718e
|
@ -128,7 +128,7 @@
|
|||
"_journal/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109",
|
||||
"c/types.md": "cf3e66e5aee58a94db3fdf0783908555",
|
||||
"logic/quantification.md": "37655276de8da531ca2b12706a639224",
|
||||
"c/declarations.md": "defa26963137a85c2b66d7be733a7815",
|
||||
"c/declarations.md": "d2e7dcb5bbf6644651f4f25503b165e1",
|
||||
"algorithms/sorting/bubble-sort.md": "16dad1016dc6555163e42ba20f1d152d",
|
||||
"_journal/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
|
||||
"_journal/2024-01/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970",
|
||||
|
@ -143,7 +143,7 @@
|
|||
"_journal/2024-02/2024-02-01.md": "3aa232387d2dc662384976fd116888eb",
|
||||
"_journal/2024-02/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
|
||||
"_journal/2024-02-11.md": "afee9f502b61e17de231cf2f824fbb32",
|
||||
"binary/endianness.md": "29c0aea671aa25aead580e9431aba8cc",
|
||||
"binary/endianness.md": "54c86119d0b7fadcc0ee86da2ef5b900",
|
||||
"logic/normal-form.md": "f8fd5ea205dfb7e331356b0574f0fe14",
|
||||
"_journal/2024-02-12.md": "240d17f356305de9c0c00282b2931acd",
|
||||
"_journal/2024-02/2024-02-11.md": "afee9f502b61e17de231cf2f824fbb32",
|
||||
|
@ -155,11 +155,15 @@
|
|||
"logic/boolean-algebra.md": "370065481448e60aa8ffa67a437b5482",
|
||||
"_journal/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0",
|
||||
"_journal/2024-02/2024-02-12.md": "618c0035a69b48227119379236a02f44",
|
||||
"binary/shifts.md": "4c8fccaa2a5a38041b8708ace97319df",
|
||||
"binary/shifts.md": "146ee4898faa13b26f00a31024020c2e",
|
||||
"_journal/2024-02-14.md": "76d1b607470305fb3f00a47b8e9ece27",
|
||||
"_journal/2024-02/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0",
|
||||
"_journal/2024-02-15.md": "575ba46d692795d9606de9e635d1f4ac",
|
||||
"_journal/2024-02/2024-02-14.md": "aa009f9569e175a8104b0537ebcc5520"
|
||||
"_journal/2024-02/2024-02-14.md": "aa009f9569e175a8104b0537ebcc5520",
|
||||
"_journal/2024-02-16.md": "aacf3fff471c47bf0251849f81539555",
|
||||
"_journal/2024-02/2024-02-15.md": "16cb7563d404cb543719b7bb5037aeed",
|
||||
"algebra/floor-ceiling.md": "114d4f455fc9729ebac704752d955fcf",
|
||||
"algebra/index.md": "90b842eb694938d87c7c68779a5cacd1"
|
||||
},
|
||||
"fields_dict": {
|
||||
"Basic": [
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
title: "2024-02-16"
|
||||
---
|
||||
|
||||
- [x] Anki Flashcards
|
||||
- [x] KoL
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [ ] OGS (1 Life & Death Problem)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
- [ ] Interview Prep (1 Practice Problem)
|
||||
- [ ] Log Work Hours (Max 3 hours)
|
||||
|
||||
* Read "Queries, Modeling, and Transformation" of "Fundamentals of Data Engineering".
|
||||
* Deleted many notes on shifting. Will wait until I look deeper into the actual representations of integral types before re-introducing.
|
||||
* Spent time deriving properties of floor/ceiling functions and analogues in C. Added many more notes on partitioning arrays in halves.
|
|
@ -0,0 +1,278 @@
|
|||
---
|
||||
title: Floors & Ceilings
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: algebra algorithm
|
||||
tags:
|
||||
- algebra
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The **floor** of $x$ is the greatest integer less than $x$. The **ceiling** of $x$ is the least integer greater than $x$. These values are denoted $\lfloor x \rfloor$ and $\lceil x \rceil$ respectively.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is the floor of $x$ denoted?
|
||||
Back: $\lfloor x \rfloor$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779607-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the floor of $x$?
|
||||
Back: The greatest integer less than $x$.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779649-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is the ceiling of $x$ denoted?
|
||||
Back: $\lceil x \rceil$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779656-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the ceiling of $x$?
|
||||
Back: The least integer greater than $x$.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779663-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
When does $\lfloor x / 2 \rfloor = \lceil x / 2 \rceil$?
|
||||
Back: When $x$ is even.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779668-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
When does $\lfloor x / 2 \rfloor \neq \lceil x / 2 \rceil$?
|
||||
Back: When $x$ is odd.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779674-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does $\lceil x \rceil - \lfloor x \rceil$ equal?
|
||||
Back: Either $0$ or $1$.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779681-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What can be said about $x$ if $\lceil x \rceil - \lfloor x \rceil = 0$?
|
||||
Back: $x$ is even.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779687-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What can be said about $x$ if $\lceil x \rceil - \lfloor x \rceil = 1$?
|
||||
Back: $x$ is odd.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779693-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What C operator corresponds to floor division?
|
||||
Back: None.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779699-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
When does C operator `/` behave like floor division?
|
||||
Back: When the result is a nonnegative value.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779705-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
When does C operator `/` behave like ceiling division?
|
||||
Back: When the result is a nonpositive value.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779710-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What C operator corresponds to ceiling division?
|
||||
Back: None.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708110779716-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How does C evaluate `10 / 3`?
|
||||
Back: `3`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
Tags: c
|
||||
<!--ID: 1708110779720-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How does C evaluate `floor(10.f / 3)`?
|
||||
Back: `3`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
Tags: c
|
||||
<!--ID: 1708110779725-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How does C evaluate `ceil(10.f / 3)`?
|
||||
Back: `4`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
Tags: c
|
||||
<!--ID: 1708110779729-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How does C evaluate `-10 / 3`?
|
||||
Back: `-3`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
Tags: c
|
||||
<!--ID: 1708110779734-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How does C evaluate `floor(-10.f / 3)`?
|
||||
Back: `-4`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
Tags: c
|
||||
<!--ID: 1708110779738-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How does C evaluate `ceil(-10.f / 3)`?
|
||||
Back: `-3`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
Tags: c
|
||||
<!--ID: 1708110779742-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given $r = \lfloor (p + q) / 2 \rfloor$, fair partitioning requires `A[r]` to be included in which of `A[p..r-1]` or `A[r+1..q]`?
|
||||
Back: `A[p..r-1]`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115109770-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given $r = \lfloor (p + q) / 2 \rfloor$, when is `A[p..r]` or `A[r+1..q]` equally sized?
|
||||
Back: When `A[p..q]` has even size.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115745322-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given $r = \lceil (p + q) / 2 \rceil$, fair partitioning requires `A[r]` to be included in which of `A[p..r-1]` or `A[r+1..q]`?
|
||||
Back: `A[r+1..q]`
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115109777-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
If `A[p..q]` has odd size, what `r` most fairly allows partitions `A[p..r]` and `A[r+1..q]`?
|
||||
Back: $r = \lfloor (p + q) / 2 \rfloor$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708114757958-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
If `A[p..q]` has odd size, what `r` most fairly allows partitions `A[p..r-1]` and `A[r..q]`?
|
||||
Back: $r = \lceil (p + q) / 2 \rceil$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708114757961-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
If `A[p..q]` has odd size, what `r` ensures `A[p..r-1]` has same size as `A[r+1..q]`?
|
||||
Back: $r = \lfloor (p + q) / 2 \rfloor = \lceil (p + q) / 2 \rceil$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708114757964-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
If `A[p..q]` has even size, what `r` most fairly allows partitions `A[p..r]` and `A[r+1..q]`?
|
||||
Back: $r = \lfloor (p + q) / 2 \rfloor$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708114757968-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
If `A[p..q]` has even size, what `r` most fairly allows partitions `A[p..r-1]` and `A[r..q]`?
|
||||
Back: $r = \lceil (p + q) / 2 \rceil$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708114757971-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given `A[p..q]` and $r = \lfloor (p + q) / 2 \rfloor$, how does the size of `A[p..r]` compare to `A[r+1..q]`?
|
||||
Back: It either has zero or one more members.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115683351-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given `A[p..q]` and $r = \lceil (p + q) / 2 \rceil$, how does the size of `A[p..r-1]` compare to `A[r..q]`?
|
||||
Back: It either has zero or one fewer members.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115683354-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given `A[p..q]` and $r = \lfloor (p + q) / 2 \rfloor$, how does the size of `A[p..r-1]` compare to `A[r..q]`?
|
||||
Back: It either has one or two fewer members.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115683358-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given `A[p..q]` and $r = \lceil (p + q) / 2 \rceil$, how does the size of `A[p..r]` compare to `A[r+1..q]`?
|
||||
Back: It either has one or two more members.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115683362-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given `A[p..q]` and $r = \lfloor (p + q) / 2 \rfloor$, *why* is the size of `A[p..r]` potentially larger than `A[r+1..q]`?
|
||||
Back: If `A[p..q]` has odd size, `A[p..r]` contains the midpoint.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708115683366-->
|
||||
END%%
|
||||
|
||||
## References
|
||||
|
||||
* Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
title: Algebra
|
||||
---
|
|
@ -38,7 +38,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
What is endianness?
|
||||
Back: The ordering of bytes of a multibyte object.
|
||||
Back: The ordering of bytes of a multi-byte object.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1707661283771-->
|
||||
END%%
|
||||
|
|
|
@ -20,30 +20,12 @@ Left shift operations (`<<`) drop the `k` most significant bits and fills the ri
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is $2^n$ written in binary?
|
||||
How is decimal value $2^n$ written in binary?
|
||||
Back: As `1` followed by $n$ zeros.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1707432641574-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is $2^n$ written using bitwise shift operators?
|
||||
Back: `1 << n`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tag: c
|
||||
<!--ID: 1707432641576-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What decimal value does `1 << n` translate to?
|
||||
Back: $2^n$
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tag: c
|
||||
<!--ID: 1707432641577-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What kinds of left shift operations are there?
|
||||
|
@ -52,24 +34,6 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1707854589773-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many most significant bits are dropped on a left shift by `k` (e.g. `<< k`)?
|
||||
Back: `k`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707854589778-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many zeros exist in the result of a left shift by `k` (e.g. `<< k`)?
|
||||
Back: At least `k`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707854589781-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What kinds of right shift operations are there?
|
||||
|
@ -94,39 +58,11 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1707854589789-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many least significant bits are dropped on a right shift by `k` (e.g. `>> k`)?
|
||||
Back: `k`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707854589792-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many zeros exist in the result of a logical right shift by `k` (e.g. `>> k`)?
|
||||
Back: At least `k`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707854589794-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many zeros exist in the result of an arithmetic right shift by `k` (e.g. `>> k`)?
|
||||
Back: Zero or more.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707854589797-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What kind of right shift operation is *usually* applied to signed numbers?
|
||||
Back: Arithmetic.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707854589801-->
|
||||
END%%
|
||||
|
||||
|
@ -135,7 +71,6 @@ Basic
|
|||
What kind of right shift operation is applied to unsigned numbers?
|
||||
Back: Logical.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707854589804-->
|
||||
END%%
|
||||
|
||||
|
@ -158,24 +93,6 @@ END%%
|
|||
|
||||
In C, it is undefined behavior to shift by more than the width $w$ of an integral type. Typically though, only the last $w$ bits are considered in the computation. For example, given `int32_t x`, `(x << 32) = (x << 0)`.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
According to the C standard, what is the result of shifting an `int32_t` value by `32`?
|
||||
Back: It is undefined behavior.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707873410765-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
According to the C standard, what is the result of shifting an `int32_t` value by a negative value?
|
||||
Back: It is undefined behavior.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707873410773-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Ignoring UB, what *typically* happens when shifting an `int32_t` by `k ≥ 32` bits?
|
||||
|
@ -194,101 +111,6 @@ Tags: c
|
|||
<!--ID: 1707873410780-->
|
||||
END%%
|
||||
|
||||
## Arithmetic
|
||||
|
||||
Shifting left by a single bit is equivalent to multiplication by $2$. Likewise, logically shifting right is equivalent to floor division by $2$. This is most clearly seen by examining the decimal expansion of a binary value. For example, consider $$001101_2 = 2^3 + 2^2 + 2^0$$
|
||||
|
||||
Multiplying by $2$ yields $$2 \cdot (2^3 + 2^2 + 2^0) = 2^4 + 2^3 + 2^1 = 011010_2$$
|
||||
|
||||
Dividing by $2$ yields $$(2^3 + 2^2 + 2^0) / 2 = 2^2 + 2^1 = 000110_2$$
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Multiplication by 2 is equivalent to what bitwise shift operation?
|
||||
Back: Left shifting by 1 bit.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708009783552-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Floor division by 2 is equivalent to what bitwise shift operation?
|
||||
Back: Logical right shifting by 1 bit.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708009783562-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Ceiling division by 2 is equivalent to what bitwise shift operation?
|
||||
Back: None.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708009783565-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
{1:Multiplication} by 2 is to {2:left shifts} whereas {2:floor division} by 2 is to {1:logical right shifts}.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708009783568-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What arithmetic operation is equivalent to shifting left by $n$ bits?
|
||||
Back: Multiplication by $2^n$.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708009783571-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
When is $2n + 1$ equivalent to a one-bit cyclic shift left?
|
||||
Back: When $n$'s leading bit is `1`.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708012138055-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What arithmetic operation is equivalent to a one-bit cyclic shift left?
|
||||
Back: Given $n$ with no leading zeros, $2n + 1$.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708012138062-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What arithmetic operation is equivalent to logically shifting right by $n$ bits?
|
||||
Back: Floor division by $2^n$.
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708009783574-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given $n = 0110_2$, what is the binary value of $2n$?
|
||||
Back: $1100_2$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708012138065-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given $n = 0110_2$, what is the binary value of $2n + 1$?
|
||||
Back: $1101_2$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708012138068-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given $n = 0110_2$, what is the binary value of $\lfloor n / 2 \rfloor$?
|
||||
Back: $0011_2$
|
||||
Reference: Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
|
||||
<!--ID: 1708012138071-->
|
||||
END%%
|
||||
|
||||
## References
|
||||
|
||||
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
|
|
|
@ -62,7 +62,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What word sizes are typically nowadays?
|
||||
What word sizes are typical nowadays?
|
||||
Back: 32- and 64-bit word sizes.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1707657889230-->
|
||||
|
|
Loading…
Reference in New Issue