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: manuscript/BashScripting/arithmetic-expression.md
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -263,7 +263,7 @@ Represent the following two-byte integers in the two's complement and add them:
263
263
264
264
You have learned how a computer represents numbers in memory. Would you need this knowledge in practice?
265
265
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.
267
267
268
268
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.
269
269
@@ -817,19 +817,22 @@ The bitwise AND operate the numbers instead of Boolean expressions. These are st
817
817
818
818
3. Take the bits of the numbers in the same position and apply the logical AND for them.
819
819
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:
821
821
{line-numbers: false}
822
822
```
823
823
5 = 101
824
824
3 = 11
825
825
```
826
826
827
+
827
828
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:
828
829
{line-numbers: false}
829
830
```
830
831
3 = 011
831
832
```
832
833
834
+
You should convert a number in the two's complement if it is negative.
835
+
833
836
Now you should apply the logical AND for each pair of bits of the numbers. You can write the numbers in columns for convenience:
834
837
{line-numbers: false}
835
838
```
@@ -855,7 +858,7 @@ echo $((5 & 3))
855
858
856
859
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.
857
860
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:
859
862
{line-numbers: false}
860
863
```
861
864
10 = 1010
@@ -893,7 +896,7 @@ echo $((10 | 6))
893
896
894
897
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".
895
898
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:
897
900
{line-numbers: false}
898
901
```
899
902
12 = 1100
@@ -951,15 +954,15 @@ Any bit shift operation takes two operands. The first one is some integer, which
951
954
952
955
Here is an algorithm for doing the logical bit shift:
953
956
954
-
1. Represent the integer in the two's complement.
957
+
1. Represent the integer in binary.
955
958
956
959
2. Discard the required amount of bits on the RHS for the right shift and the LHS for the left shift.
957
960
958
961
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.
959
962
960
963
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.
961
964
962
-
First, you represent the number in the two's complement:
Copy file name to clipboardExpand all lines: manuscript/BashScripting/conditional-statement.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -506,7 +506,7 @@ You can choose the mode by passing a command-line option to the script. Table 3-
506
506
|`-c`| Archiving with compression |
507
507
|`-x`| Unarchiving |
508
508
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.
510
510
511
511
You can check the script option using the `if` statement. Listing 3-12 shows how this solution looks like.
Copy file name to clipboardExpand all lines: manuscript/BashScripting/loop-operators.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ When the script receives the response from the server, it should print a message
101
101
102
102
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**.
103
103
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.
105
105
106
106
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.
Copy file name to clipboardExpand all lines: manuscript/BashShell/file-system.md
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -751,7 +751,9 @@ Here is an example of using the `-r` option:
751
751
grep -r "free software" .
752
752
```
753
753
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:
Copy file name to clipboardExpand all lines: manuscript/BashShell/tools.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ Now we have everything to install MSYS2. Follow these steps for doing it:
47
47
48
48
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.
49
49
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.
51
51
52
52
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.
0 commit comments