Skip to content

Commit 685883f

Browse files
committed
Minor fixes
1 parent a4122a9 commit 685883f

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

manuscript/BashScripting/arithmetic-expression.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ Represent the following two-byte integers in the two's complement and add them:
263263

264264
You have learned how a computer represents numbers in memory. Would you need this knowledge in practice?
265265

266-
Modern programming languages take care of converting numbers to the correct format. For example, you declare a signed integer variable in decimal notation. You do not need to worry about how the computer stores it in memory. If the variable becomes negative, the computer applies the two's complement representation automatically.
266+
Modern programming languages take care of converting numbers to the correct format. For example, you declare a signed integer variable in decimal notation. You do not need to worry about how the computer stores it in memory. It stores all numbers in two's complement representation automatically.
267267

268268
There are cases when you want to treat a variable as a set of bits. You declare it as a positive integer in this case. You should operate it in hexadecimal. Please do not convert this variable to decimal. This way, you avoid the problems of converting numbers.
269269

@@ -817,19 +817,22 @@ The bitwise AND operate the numbers instead of Boolean expressions. These are st
817817

818818
3. Take the bits of the numbers in the same position and apply the logical AND for them.
819819

820-
Here is an example. You want to calculate the bitwise AND for numbers 5 and 3. First, you should represent them in the two's complement like this:
820+
Here is an example. You want to calculate the bitwise AND for numbers 5 and 3. First, you should represent their absolute values in binary like this:
821821
{line-numbers: false}
822822
```
823823
5 = 101
824824
3 = 11
825825
```
826826

827+
827828
The number 3 has fewer bits than 5. Therefore, you have to add an extra zero on its left side. This way, you get the following representation of the number 3:
828829
{line-numbers: false}
829830
```
830831
3 = 011
831832
```
832833

834+
You should convert a number in the two's complement if it is negative.
835+
833836
Now you should apply the logical AND for each pair of bits of the numbers. You can write the numbers in columns for convenience:
834837
{line-numbers: false}
835838
```
@@ -855,7 +858,7 @@ echo $((5 & 3))
855858

856859
The bitwise OR operation works similarly as bitwise AND. The only difference is it applies logical OR instead of AND for each pair of bits.
857860

858-
Here is an example. Suppose that you need to calculate the bitwise OR for the numbers 10 and 6. First, you should write them in the two's complement representation this way:
861+
Here is an example. Suppose that you need to calculate the bitwise OR for the numbers 10 and 6. First, you should write them in binary this way:
859862
{line-numbers: false}
860863
```
861864
10 = 1010
@@ -893,7 +896,7 @@ echo $((10 | 6))
893896

894897
The bitwise exclusive OR (XOR) operation is similar to the bitwise OR. You should replace the logical OR with the **exclusive OR** when handling the bits of the numbers there. The exclusive OR returns "false" only when both operands have the same values. Otherwise, it returns "true".
895898

896-
Let's calculate the exclusive OR for the numbers 12 and 5. First, represent them in the two's complement:
899+
Let's calculate the exclusive OR for the numbers 12 and 5. First, represent them in binary:
897900
{line-numbers: false}
898901
```
899902
12 = 1100
@@ -951,15 +954,15 @@ Any bit shift operation takes two operands. The first one is some integer, which
951954

952955
Here is an algorithm for doing the logical bit shift:
953956

954-
1. Represent the integer in the two's complement.
957+
1. Represent the integer in binary.
955958

956959
2. Discard the required amount of bits on the RHS for the right shift and the LHS for the left shift.
957960

958961
3. Append zeroes on the opposite side of the number. This is LHS for the right shift and RHS for the left shift. The amount of zeroes matches the number of shifted bits.
959962

960963
Here is an example. You need to do a logical right shift of the unsigned integer 58 by three bits. The integer occupies one byte of memory.
961964

962-
First, you represent the number in the two's complement:
965+
First, you represent the number in binary:
963966
{line-numbers: false}
964967
```
965968
58 = 0011 1010

manuscript/BashScripting/conditional-statement.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ You can choose the mode by passing a command-line option to the script. Table 3-
506506
| `-c` | Archiving with compression |
507507
| `-x` | Unarchiving |
508508

509-
I> Always follow the [POSIX agreement](https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html) and its [GNU extension](https://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html) when choosing options and parameters format for your scripts. Then users can learn them faster.
509+
I> Always follow the [POSIX convention](https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html) and its [GNU extension](https://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html) when choosing options and parameters format for your scripts. Then users can learn them faster.
510510

511511
You can check the script option using the `if` statement. Listing 3-12 shows how this solution looks like.
512512

manuscript/BashScripting/loop-operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ When the script receives the response from the server, it should print a message
101101

102102
You can call the [`ping`](https://en.wikipedia.org/wiki/Ping_(networking_utility)) utility to send a request to the server. The utility uses the [ICMP](https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol) **protocol**.
103103

104-
The protocol is an agreement for the format of messages between the computers of the network. The ICMP protocol describes the messages to serve the network. For example, you need them to check if some computer is available.
104+
The protocol is an agreement for the format of messages between the computers of the network. The ICMP protocol describes the error messages and packets with operational information. For example, you need them to check if some computer is available.
105105

106106
When calling the `ping` utility, you should specify an [IP address](https://en.wikipedia.org/wiki/IP_address) or [URL](https://en.wikipedia.org/wiki/URL) of the target **host**. A host is a computer or device connected to the network.
107107

manuscript/BashShell/file-system.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,9 @@ Here is an example of using the `-r` option:
751751
grep -r "free software" .
752752
```
753753

754-
This command finds the "free software" phrase in the files of the current directory. It processes the hidden objects too. If you work on Linux or macOS, prefer the `-R` option instead of `-r`. It forces `grep` to follow [**symbol links**](https://en.wikipedia.org/wiki/Symbolic_link) when searching. Here is an example:
754+
This command finds the "free software" phrase in the files of the current directory. It processes the hidden objects too.
755+
756+
If you work on Linux or macOS, prefer the `-R` option instead of `-r`. It forces `grep` to follow [**symbol links**](https://en.wikipedia.org/wiki/Symbolic_link) when searching. Here is an example:
755757
{line-numbers: false, format: Bash}
756758
```
757759
grep -R "free software" .

manuscript/BashShell/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Now we have everything to install MSYS2. Follow these steps for doing it:
4747

4848
4. The next window suggests you to choose the application name for the Windows "Start" menu. Leave it unchanged and click the "Next" button. Then the installation process starts.
4949

50-
4. When the installation finishes, click the "Finish" button. It closes the installer window.
50+
5. When the installation finishes, click the "Finish" button. It closes the installer window.
5151

5252
You have installed the MSYS2 Unix environment on your hard drive. You can find its files in the `C:\msys64` directory if you did not change the default installation path. Go to this directory and run the `msys2.exe` file. It opens the window where you can work with the Bash shell. Figure 2-4 shows this window.
5353

manuscript/answers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,13 @@ Let's perform bit-shifts for the signed two-byte integers. Then you will get the
655655
0110 0100 0011 0 = 0000 1100 1000 0110 = 3206
656656
657657
* 25649 << 2 = 0110 0100 0011 0001 << 2 =
658-
10 0100 0011 0001 -> 1001 0000 1100 0100 -> 1110 1111 0011 1100 = -28476
658+
10 0100 0011 0001 -> 1001 0000 1100 0100 = -28476
659659
660660
* -9154 >> 4 = 1101 1100 0011 1110 >> 4 =
661-
1101 1100 0011 -> 1111 1101 1100 0011 -> 1000 0010 0011 1101 = -573
661+
1101 1100 0011 -> 1111 1101 1100 0011 = -573
662662
663663
* -9154 << 3 = 1101 1100 0011 1110 << 3 =
664-
1 1100 0011 1110 -> 1110 0001 1111 0000 -> 1001 1110 0001 0000 = -7696
664+
1 1100 0011 1110 -> 1110 0001 1111 0000 = -7696
665665
```
666666

667667
Here are the Bash commands for checking the calculations:

0 commit comments

Comments
 (0)