Skip to content

Commit 43438ca

Browse files
authored
[Bitwise Operations and Complex Numbers Concepts]: Fixed Typos & Grammar (#4194)
* Fixed typos and grammar for bitwise and complex number concepts. * Applied fixes from code review.
1 parent 088a89a commit 43438ca

5 files changed

Lines changed: 21 additions & 23 deletions

File tree

concepts/bitwise-operators/about.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ See the section below for details.
112112
In decimal representation, we distinguish positive and negative numbers by using a `+` or `-` sign to the left of the digits.
113113
Using these symbols at a binary level proved inefficient for digital computing and raised the problem that `+0` is not the same as `-0`.
114114

115-
Rather than using `-` and `+`, all modern computers use a [`twos-complement`][twos-complement] representation for negative numbers, right down to the silicon chip level.
115+
Rather than using `-` and `+`, all modern computers use a [`two's complement`][twos-complement] representation for negative numbers, right down to the silicon chip level.
116116
This means that all bits are inverted and a number is _**interpreted as negative**_ if the left-most bit (also termed the "most significant bit", or MSB) is a `1`.
117117
Positive numbers have an MSB of `0`.
118118
This representation has the advantage of only having one version of zero, so that the programmer doesn't have to manage `-0` and `+0`.
@@ -145,21 +145,21 @@ This is **not** the `0b10011001` we would see in languages with fixed-size integ
145145
The `~` operator only works as expected with _**unsigned**_ byte or integer types, or with fixed-sized integer types.
146146
These numeric types are supported in third-party packages such as [`NumPy`][numpy], [`pandas`][pandas], and [`sympy`][sympy] but not in core Python.
147147

148-
In practice, Python programmers quite often use the shift operators described below and `& | ^` with positive numbers only.
148+
In practice, Python programmers quite often use `&`, `|`, `^`, and the shift operators described below with positive numbers only.
149149
Bitwise operations with negative numbers are much less common.
150150
One technique is to add [`2**32 (or 1 << 32)`][unsigned-int-python] to a negative value to make an `int` unsigned, but this gets difficult to manage.
151151
Another strategy is to work with the [`ctypes`][ctypes-module] module, and use c-style integer types, but this is equally unwieldy.
152152

153153

154154
## [`Shift operators`][bitwise-shift-operators]
155155

156-
The left-shift operator `x << y` simply moves all the bits in `x` by `y` places to the left, filling the new gaps with zeros.
157-
Note that this is arithmetically identical to multiplying a number by `2**y`.
156+
The left-shift operator `x << y` moves all the bits in `x` by `y` places to the left, filling the new gaps with zeros.
157+
Note that this is arithmetically identical to multiplying a number by `(2**y)`.
158158

159159
The right-shift operator `x >> y` does the opposite.
160-
This is arithmetically identical to integer division `x // 2**y`.
160+
This is arithmetically identical to integer division `x // (2**y)`.
161161

162-
Keep in mind the previous section on negative numbers and their pitfalls when shifting.
162+
Keep in mind the previous section on negative numbers and their pitfalls when shifting them in Python.
163163

164164

165165
```python
@@ -191,7 +191,7 @@ Keep in mind the previous section on negative numbers and their pitfalls when sh
191191
[symmetric-difference]: https://math.stackexchange.com/questions/84184/relation-between-xor-and-symmetric-difference#:~:text=It%20is%20the%20same%20thing,they%20are%20indeed%20the%20same.
192192
[sympy]: https://docs.sympy.org/latest/modules/codegen.html#predefined-types
193193
[tilde]: https://en.wikipedia.org/wiki/Tilde
194-
[twos-complement]: https://en.wikipedia.org/wiki/Two%27s_complement#:~:text=Two's%20complement%20is%20the%20most,number%20is%20positive%20or%20negative.
194+
[twos-complement]: https://en.wikipedia.org/wiki/Two%27s_complement
195195
[unsigned-int-python]: https://stackoverflow.com/a/20768199
196196
[xor-cipher]: https://en.wikipedia.org/wiki/XOR_cipher
197197
[xor]: https://stackoverflow.com/a/2451393

concepts/bitwise-operators/introduction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Introduction
22

3-
Down at the hardware level, transistors can only be on or off: two states that we traditionally represent with `1` and `0`.
3+
Down at the hardware level, [transistors can only be on or off][how-transistors-work]: two states that we traditionally represent with `1` and `0`.
44
These are the [`binary digits`][binary-digits], abbreviated as [`bits`][bits].
55
Awareness of `bits` and `binary` is particularly important for systems programmers working in low-level languages.
6-
76
However, for most of the history of computing the programming priority has been to find increasingly sophisticated ways to _abstract away_ this binary reality.
87

98

109
In Python (and many other [high-level programming languages][high-level-language]), we work with `int`, `float`, `string` and other defined _types_, up to and including audio and video formats.
11-
We let the Python internals take care of (eventually) translating everything to bits.
10+
Python internals take care of (_eventually_) translating all the higher-level data to bits.
1211

1312

1413
Nevertheless, using [bitwise-operators][python-bitwise-operators] and [bitwise operations][python-bitwise-operations] can sometimes have significant advantages in speed and memory efficiency, even in a high-level language like Python.
1514

1615
[high-level-language]: https://en.wikipedia.org/wiki/High-level_programming_language
16+
[how-transistors-work]: https://www.build-electronic-circuits.com/how-transistors-work/
1717
[binary-digits]: https://www.khanacademy.org/computing/computers-and-internet/xcae6f4a7ff015e7d:digital-information/xcae6f4a7ff015e7d:binary-numbers/v/the-binary-number-system
1818
[bits]: https://en.wikipedia.org/wiki/Bit
1919
[python-bitwise-operations]: https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations

concepts/bitwise-operators/links.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
[
2-
{
3-
"url": "https://wiki.python.org/moin/BitwiseOperators/",
4-
"description": "BitwiseOperators on the Python wiki."
5-
},
62
{
73
"url": "https://realpython.com/python-bitwise-operators",
84
"description": "Real Python: Bitwise Operators in Python."

concepts/complex-numbers/about.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
`Complex numbers` are not complicated.
44
They just need a less alarming name.
55

6-
They are so useful, especially in engineering and science, that Python includes [`complex`][complex] as a standard numeric type alongside integers ([`int`s][ints]) and floating-point numbers ([`float`s][floats]).
6+
They are so usefulespecially in engineering and sciencethat Python includes [`complex`][complex] as a standard numeric type, alongside integers ([`int`s][ints]) and floating-point numbers ([`float`s][floats]).
77

88

99
## Basics
@@ -143,7 +143,7 @@ Any [mathematical][math-complex] or [electrical engineering][engineering-complex
143143
Alternatively, Exercism has a `Complex Numbers` practice exercise where you can implement a complex number class with these operations from first principles.
144144

145145

146-
Integer division is ___not___ possible on complex numbers, so the `//` and `%` operators and `divmod()` functions will fail for the complex number type.
146+
Integer division is ___not___ possible on complex numbers, so the `//` and `%` operators and the `divmod()` function will fail for the complex number type.
147147

148148

149149
There are two functions implemented for numeric types that are very useful when working with complex numbers:
@@ -235,13 +235,13 @@ If you are reading this on any sort of screen, you are utterly dependent on some
235235

236236
1. __Semiconductor chips__.
237237
- These make no sense in classical physics and can only be explained (and designed) by quantum mechanics (QM).
238-
- In QM, everything is complex-valued by definition. (_its waveforms all the way down_)
238+
- In QM, everything is complex-valued by definition. (_it's waveforms all the way down_)
239239

240-
2. __The Fast Fourier Transform algorithm__.
240+
2. __The Fast Fourier Transform (FFT) algorithm__.
241241
- FFT is an application of complex numbers, and it is in _everything_ connected to sound transmission, audio processing, photos, and video.
242242

243-
-MP3 and other audio formats use FFT for compression, ensuring more audio can fit within a smaller storage space.
244-
- JPEG compression and MP4 video, among many other image and video formats also use FTT for compression.
243+
- MP3 and other audio formats use FFT for compression, ensuring more audio can fit within a smaller storage space.
244+
- JPEG compression and MP4 video, among many other image and video formats, also use FTT for compression.
245245

246246
- FFT is also deployed in the digital filters that allow cellphone towers to separate your personal cell signal from everyone else's.
247247

concepts/complex-numbers/introduction.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
`Complex numbers` are not complicated.
44
They just need a less alarming name.
55

6-
They are so useful, especially in engineering and science (_everything from JPEG compression to quantum mechanics_), that Python includes [`complex`][complex] as a standard numeric type alongside integers ([`int`s][ints]) and floating-point numbers ([`float`s][floats]).
6+
7+
They are so useful — especially in engineering and science — that Python includes [`complex`][complex] as a standard numeric type, alongside integers ([`int`s][ints]) and floating-point numbers ([`float`s][floats]).
8+
79

810
A `complex` value in Python is essentially a pair of floating-point numbers:
911

@@ -74,13 +76,13 @@ There are two common ways to create complex numbers.
7476

7577
Most of the [`operators`][operators] used with floats and ints also work with complex numbers.
7678

77-
Integer division is _**not**_ possible on complex numbers, so the `//` and `%` operators and `divmod()` functions will fail for the complex number type.
79+
Integer division is _**not**_ possible on complex numbers, so the `//` and `%` operators and the `divmod()` function will fail for the complex number type.
7880

7981
Explaining the rules for complex number multiplication and division is out of scope for this concept (_and you are unlikely to have to perform those operations "by hand" very often_).
8082

8183
Any [mathematical][math-complex] or [electrical engineering][engineering-complex] introduction to complex numbers will cover these scenarios, should you want to dig into the topic.
8284

83-
The Python standard library has a [`math`][math-module] module full of useful functionality for working with real numbers and the [`cmath`][cmath] module is its equivalent for working with complex numbers.
85+
The Python standard library has a [`math`][math-module] module full of useful functionality for working with real numbers, and the [`cmath`][cmath] module is its equivalent for working with complex numbers.
8486

8587

8688
[cmath]: https://docs.python.org/3/library/cmath.html

0 commit comments

Comments
 (0)