You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/bitwise-operators/about.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,7 +112,7 @@ See the section below for details.
112
112
In decimal representation, we distinguish positive and negative numbers by using a `+` or `-` sign to the left of the digits.
113
113
Using these symbols at a binary level proved inefficient for digital computing and raised the problem that `+0` is not the same as `-0`.
114
114
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.
116
116
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`.
117
117
Positive numbers have an MSB of `0`.
118
118
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
145
145
The `~` operator only works as expected with _**unsigned**_ byte or integer types, or with fixed-sized integer types.
146
146
These numeric types are supported in third-party packages such as [`NumPy`][numpy], [`pandas`][pandas], and [`sympy`][sympy] but not in core Python.
147
147
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.
149
149
Bitwise operations with negative numbers are much less common.
150
150
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.
151
151
Another strategy is to work with the [`ctypes`][ctypes-module] module, and use c-style integer types, but this is equally unwieldy.
152
152
153
153
154
154
## [`Shift operators`][bitwise-shift-operators]
155
155
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)`.
158
158
159
159
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)`.
161
161
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.
163
163
164
164
165
165
```python
@@ -191,7 +191,7 @@ Keep in mind the previous section on negative numbers and their pitfalls when sh
Copy file name to clipboardExpand all lines: concepts/bitwise-operators/introduction.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
# Introduction
2
2
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`.
4
4
These are the [`binary digits`][binary-digits], abbreviated as [`bits`][bits].
5
5
Awareness of `bits` and `binary` is particularly important for systems programmers working in low-level languages.
6
-
7
6
However, for most of the history of computing the programming priority has been to find increasingly sophisticated ways to _abstract away_ this binary reality.
8
7
9
8
10
9
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.
12
11
13
12
14
13
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.
Copy file name to clipboardExpand all lines: concepts/complex-numbers/about.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
`Complex numbers` are not complicated.
4
4
They just need a less alarming name.
5
5
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 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]).
7
7
8
8
9
9
## Basics
@@ -143,7 +143,7 @@ Any [mathematical][math-complex] or [electrical engineering][engineering-complex
143
143
Alternatively, Exercism has a `Complex Numbers` practice exercise where you can implement a complex number class with these operations from first principles.
144
144
145
145
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.
147
147
148
148
149
149
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
235
235
236
236
1.__Semiconductor chips__.
237
237
- 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_)
239
239
240
-
2.__The Fast Fourier Transform algorithm__.
240
+
2.__The Fast Fourier Transform (FFT) algorithm__.
241
241
- FFT is an application of complex numbers, and it is in _everything_ connected to sound transmission, audio processing, photos, and video.
242
242
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.
245
245
246
246
- FFT is also deployed in the digital filters that allow cellphone towers to separate your personal cell signal from everyone else's.
Copy file name to clipboardExpand all lines: concepts/complex-numbers/introduction.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,9 @@
3
3
`Complex numbers` are not complicated.
4
4
They just need a less alarming name.
5
5
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
+
7
9
8
10
A `complex` value in Python is essentially a pair of floating-point numbers:
9
11
@@ -74,13 +76,13 @@ There are two common ways to create complex numbers.
74
76
75
77
Most of the [`operators`][operators] used with floats and ints also work withcomplex numbers.
76
78
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 andthe `divmod()`function will fail for the complex number type.
78
80
79
81
Explaining the rules forcomplex 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_).
80
82
81
83
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.
82
84
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 withcomplex 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 withcomplex numbers.
0 commit comments