{"id":29426,"date":"2023-12-04T06:22:41","date_gmt":"2023-12-04T06:22:41","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=29426"},"modified":"2023-12-13T03:57:31","modified_gmt":"2023-12-13T03:57:31","slug":"bash-bitwise-shift","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/","title":{"rendered":"Bitwise Shift Operator in Bash Script [3 Examples]"},"content":{"rendered":"<p style=\"text-align: justify;\">The <strong>bitwise shift operators <\/strong>(&lt;&lt; and &gt;&gt;) in Bash manipulate data at the binary level. They are commonly used in low-level programming, such as system-level programming or device driver development, where bitwise operations are used to interact with hardware registers and handle binary data at the bit level. This article aims to help you understand the usage of bitwise shift operators in a bash script with various examples. So, let&#8217;s get started!<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/Practice_Files_bash-bitwise-shift.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i> Practice Files to Use Bitwise Shift Operator in Bash Script<\/span><\/a><\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#What_are_the_Bitwise_Shift_Operators_in_Bash_Script\" >What are the Bitwise Shift Operators in Bash Script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#3_Practical_Examples_of_Using_Bitwise_Shift_Operators_in_Bash\" >3 Practical Examples of Using Bitwise Shift Operators in Bash<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#Example_1_Using_Bitwise_Shift_Operator_to_Multiply_and_Divide_with_the_Power_of_Two\" >Example 1: Using Bitwise Shift Operator to Multiply and Divide with the Power of Two<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#Example_2_Using_Bitwise_Shift_Operator_to_Convert_Decimal_to_Binary\" >Example 2: Using Bitwise Shift Operator to Convert Decimal to Binary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#Example_3_Utilizing_Bitwise_Shift_Operator_to_Toggle_a_Bit_at_a_Specific_Position\" >Example 3: Utilizing Bitwise Shift Operator to Toggle a Bit at a Specific Position<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#What_is\" >What is &lt;&lt; in bitwise?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#How_to_do_bitwise_shift\" >How to do bitwise shift?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#What_is_the_right_shift_operator_in_bash\" >What is the right shift operator in bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#Does_the_left_shift_multiply_by_2\" >Does the left shift multiply by 2?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#How_do_you_divide_by_4_in_bit_shift\" >How do you divide by 4 in bit shift?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_are_the_Bitwise_Shift_Operators_in_Bash_Script\"><\/span>What are the Bitwise Shift Operators in Bash Script?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Bitwise shift operators are programming tools that move individual binary digits to the left or right. These operators are commonly used in programming languages to manage binary data, simplify multiplication or division by powers of two, and streamline specific numerical tasks.<\/p>\n<p style=\"text-align: justify;\">There are two types of shift operators in the bash script, left bitwise shift and right bitwise shift.<\/p>\n<ol>\n<li><strong>Left Bitwise Shift (&lt;&lt;)<\/strong>: The Left Bitwise Shift (<code class=\"\" data-line=\"\">&lt;&lt;<\/code>) operator in Bash <strong>shifts the bits <\/strong>of a binary number to the <strong>left <\/strong>by a specified number of positions. Each shift to the left effectively <strong>multiplies the original number by 2 raised to the power of the shift count<\/strong>. Left shifts are often used for quick multiplication by powers of 2 in binary representation. A typical example of using a left bitwise shift operator in a bash code is as follows:\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nx=5\ny=2\nresult=$((x &lt;&lt; y))\necho &quot;Result of $x &lt;&lt; $y is $result&quot;\n<\/code><\/pre>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-29429 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/1.-Left-Bitwise-Shift-nin-bash-scrtpt.png\" alt=\"Left Bitwise Shift in bash script\" width=\"539\" height=\"112\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/1.-Left-Bitwise-Shift-nin-bash-scrtpt.png 539w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/1.-Left-Bitwise-Shift-nin-bash-scrtpt-300x62.png 300w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/>Here, The binary representation of 5 is 101. This means that when the number is shifted two positions to the left, it becomes 10100 in binary. In decimal, this is 20. Therefore, the result of the expression <code class=\"\" data-line=\"\">$((x &lt;&lt; y))<\/code> is 20. In other words, the left shift operation multiplies the original number 5 by 2 raised to the power of the shift count, which is 2. This is equivalent to 5 multiplied by 2 raised to the power of 2, which is 5*2^2 resulting in 20.<\/p>\n<\/li>\n<li><strong>Right Bitwise Shift (&gt;&gt;)<\/strong>: The Right Bitwise Shift (<code class=\"\" data-line=\"\">&gt;&gt;<\/code>) operator in Bash <strong>shifts<\/strong> <strong>the bits <\/strong>of a binary number to the <strong>right <\/strong>by a specified number of positions. Each shift to the right effectively <strong>divides the original number by 2 raised to the power of the shift count<\/strong>.An example of its implementation is displayed as follows:\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nx=16\ny=2\nresult=$((x &gt;&gt; y))\necho &quot;Result of $x &gt;&gt; $y is $result&quot;\n<\/code><\/pre>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter wp-image-29430 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/2.-Right-Bitwise-Shift-nin-bash-scrtpt.png\" alt=\"Right Bitwise Shift in bash script\" width=\"599\" height=\"114\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/2.-Right-Bitwise-Shift-nin-bash-scrtpt.png 599w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/2.-Right-Bitwise-Shift-nin-bash-scrtpt-300x57.png 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/>Here, The binary representation of 16 is 10000, and when the bit shifts by two positions to the right, the binary value changes to 100, which is equivalent to 4 in decimal. Therefore, the result of the expression <code class=\"\" data-line=\"\">$((x &gt;&gt; y))<\/code> is 4.<\/p>\n<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"3_Practical_Examples_of_Using_Bitwise_Shift_Operators_in_Bash\"><\/span>3 Practical Examples of Using Bitwise Shift Operators in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Bitwise shift operator is a very efficient and handy way to do binary operations like scaling up and down the number. You can also incorporate a bitwise shift operator to do regular tasks like finding even or odd numbers, converting decimal numbers into binary numbers, toggling a specific bit from the binary combination, etc. Here are three practical examples of bitwise shift operators in Bash:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_1_Using_Bitwise_Shift_Operator_to_Multiply_and_Divide_with_the_Power_of_Two\"><\/span>Example 1: Using Bitwise Shift Operator to Multiply and Divide with the Power of Two<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To do the multiplication and division using the bitwise shift operator use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nvalue=8\nmultiplied=$((value &lt;&lt; 2))\ndivided=$((value &gt;&gt; 1))\necho &quot;Multiplication of 8 by 2^2: $multiplied, Divided by 2: $divided&quot;\n<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>This Bash script assigns the value 8 to a variable. The bitwise left shift operation <code class=\"\" data-line=\"\">&lt;&lt;<\/code> is then applied to the value by 2 positions, resulting in the variable multiplied storing the value of 8 multiplied by 2 raised to the power of 2. Subsequently, the bitwise right shift operation <code class=\"\" data-line=\"\">&gt;&gt;<\/code> is used to shift the bits of value to the right by 1 position, and the result is stored in the variable divided. Finally, the script prints the results using the <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a>, including a message that shows the multiplication by 2^2 and the division by 2.<\/p>\n<\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-29431 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/3.-Using-Bitwise-Shift-Operator-to-Multiply-and-Divide-with-the-Power-of-Two.png\" alt=\"Using Bitwise Shift Operator to Multiply and Divide with the Power of Two\" width=\"700\" height=\"98\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/3.-Using-Bitwise-Shift-Operator-to-Multiply-and-Divide-with-the-Power-of-Two.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/3.-Using-Bitwise-Shift-Operator-to-Multiply-and-Divide-with-the-Power-of-Two-300x42.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>As shown in the image, the code outputs 32 for a left shift and 4 for a right shift on decimal 8.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_2_Using_Bitwise_Shift_Operator_to_Convert_Decimal_to_Binary\"><\/span>Example 2: Using Bitwise Shift Operator to Convert Decimal to Binary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The conversion of a decimal number to binary involves repeatedly dividing the decimal number by 2 and keeping track of the remainder. The binary representation is obtained by reading the remainder in reverse order.<\/p>\n<p style=\"text-align: justify;\">To convert a decimal number to binary using bitwise shift operators in Bash, you can use the following script as an example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Decimal number to be converted to binary\ndecimal=10\n# Initialize an empty string to store the binary representation\nbinary=&quot;&quot;\n\nwhile ((decimal &gt; 0)); do\n    #Calculate the least significant bit\n    bit=$((decimal % 2))\n   \n    # Prepend the bit to the binary string\n    binary=&quot;$bit$binary&quot;\n    \n    # Right shift the decimal number by 1\n    decimal=$((decimal &gt;&gt; 1))\ndone\necho &quot;The binary value of 10 is $binary&quot;\n<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>This Bash script converts decimal 10 to binary using a <strong>while loop<\/strong>. It calculates the <strong>LSB<\/strong> by adding the remainder of the decimal number divided by 2 to the binary string.\u00a0The decimal number is right-shifted by one position in each iteration until it becomes 0. It displays the output using the <strong>echo command<\/strong>.<\/p>\n<\/div><\/div>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-29432 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/4.-Using-Bitwise-Shift-Operator-to-Convert-Decimal-to-Binary.png\" alt=\"Using Bitwise Shift Operator to Convert Decimal to Binary\" width=\"619\" height=\"109\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/4.-Using-Bitwise-Shift-Operator-to-Convert-Decimal-to-Binary.png 619w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/4.-Using-Bitwise-Shift-Operator-to-Convert-Decimal-to-Binary-300x53.png 300w\" sizes=\"(max-width: 619px) 100vw, 619px\" \/>As the image shows, the code returns the binary representation of decimal 10 to 1010.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_3_Utilizing_Bitwise_Shift_Operator_to_Toggle_a_Bit_at_a_Specific_Position\"><\/span>Example 3: Utilizing Bitwise Shift Operator to Toggle a Bit at a Specific Position<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Toggling a bit at a specific position means changing its value from 0 to 1 or from 1 to 0 while leaving other bits unchanged. The <strong>bitwise shift operator <\/strong>plays a crucial role in this process by creating a bitmask that isolates the bit at the specified position, allowing it to be toggled independently of the other bits.<\/p>\n<p style=\"text-align: justify;\">To toggle a bit at a specific position using bitwise shift operators in Bash, you can use the following approach:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Function to convert a decimal number to binary\ndecimal_to_binary() {\n    local decimal=$1\n    local binary=&quot;&quot;\n    while ((decimal &gt; 0)); do\n        bit=$((decimal % 2))\n        binary=&quot;$bit$binary&quot;\n        decimal=$((decimal &gt;&gt; 1))\n    done\n    echo &quot;$binary&quot;\n}\n\n# Prompt the user to enter a number and position\nread -p &quot;Enter a decimal number: &quot; user_number\nread -p &quot;Enter the position to toggle (starting from 0): &quot; user_position\n\n# Toggle the bit at the specified position\nresult=$((user_number ^ (1 &lt;&lt; user_position)))\n\n# Convert the original number and the toggle value to binary\noriginal_binary=$(decimal_to_binary $user_number)\ntoggle_binary=$(decimal_to_binary $result)\n\n# Output the results\necho &quot;Original number in binary: $original_binary&quot;\necho &quot;Toggle value in binary: $toggle_binary (toggling bit at position $user_position)&quot;\necho &quot;Decimal value after toggle: $result&quot;\n<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>In this Bash script, a function named decimal_to_binary is defined to convert a decimal number to binary. The script then prompts the user to enter a <strong>decimal number <\/strong>and a <strong>position <\/strong>to toggle. It uses the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/xor\/\" target=\"_blank\" rel=\"noopener\"><strong>bitwise XOR operato<\/strong><\/a><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/xor\/\"><strong>r<\/strong><\/a> (^) and the <strong>left shift operator <\/strong>(<code class=\"\" data-line=\"\">&lt;&lt;<\/code>) to toggle the bit at the specified position, storing the result in the variable result. The script calls the <code class=\"\" data-line=\"\">decimal_to_binary<\/code> function to convert both the original decimal number and the toggle result to their binary representations. Finally, the script outputs the binary representation of the original number.<\/p>\n<\/div><\/div>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-29427 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/5.-Utilizing-Bitwise-Shift-Operator-to-Toggle-a-Bit-at-a-Specific-Position.png\" alt=\" Utilizing Bitwise Shift Operator to Toggle a Bit at a Specific Position\" width=\"825\" height=\"214\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/5.-Utilizing-Bitwise-Shift-Operator-to-Toggle-a-Bit-at-a-Specific-Position.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/5.-Utilizing-Bitwise-Shift-Operator-to-Toggle-a-Bit-at-a-Specific-Position-300x78.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/5.-Utilizing-Bitwise-Shift-Operator-to-Toggle-a-Bit-at-a-Specific-Position-768x199.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>From the image displayed above, you can observe that the binary representation of the user input <strong>9 <\/strong>is <code class=\"\" data-line=\"\">1001<\/code>. The <strong>flip operation <\/strong>is performed on the binary representation in the index position 2 (which is the third bit). After the flip, the binary representation returns a new value\u00a0 <code class=\"\" data-line=\"\">1101<\/code> where the third bit has been flipped from 0 to 1. This new binary value results in the decimal value 13.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To conclude, the <strong>bitwise shift operators <\/strong>(&lt;&lt; for left shift and &gt;&gt; for right shift) in Bash offer an efficient way to manipulate binary data. These operators prove beneficial for tasks such as rapid multiplication or division by powers of 2. Bash scripting frequently utilizes them in bitwise operations to optimize numerical computations as well. This article provides a comprehensive demonstration of the bitwise operator in bash with various examples. If you have any questions or queries related to this article, feel free to comment below. Thank you!<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"What_is\"><\/span>What is &lt;&lt; in bitwise?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In bitwise operations, <strong>&lt;&lt; is the left bitwise shift operator<\/strong>. It shifts the bits of a binary number to the left by a specified number of positions. The operation is equivalent to multiplying the original number by 2 raised to the power of the shift count.<\/p>\n<p style=\"text-align: justify;\">For example, if you have the binary number <code class=\"\" data-line=\"\">1010<\/code> and perform a left shift by 2 (<code class=\"\" data-line=\"\">1010 &lt;&lt; 2<\/code>), the result will be <code class=\"\" data-line=\"\">101000<\/code>, as each bit is shifted two positions to the left, effectively multiplying the original decimal value by 4.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_do_bitwise_shift\"><\/span>How to do bitwise shift?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The bitwise shift in Bash is performed using the <code class=\"\" data-line=\"\">&lt;&lt;<\/code> (<strong>left<\/strong> <strong>shift<\/strong>) and <code class=\"\" data-line=\"\">&gt;&gt;<\/code> (<strong>right<\/strong> <strong>shift<\/strong>) operators. The<strong> &lt;&lt; operator shifts<\/strong> the bits of a number to the <strong>left<\/strong>, effectively multiplying the number by 2 raised to the specified power. Similarly, the<strong> &gt;&gt; operator shifts<\/strong> the bits to the <strong>right<\/strong>, resulting in division by 2 raised to the specified power. For example, in the expression <code class=\"\" data-line=\"\">a &lt;&lt; b<\/code>, the bits in the binary representation of a are shifted to the left by b positions, and in <code class=\"\" data-line=\"\">a &gt;&gt; b<\/code>, the bits are shifted to the right by b positions.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_right_shift_operator_in_bash\"><\/span>What is the right shift operator in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>right shift operator (&gt;&gt;)<\/strong> is one type of bitwise operator in the bash script<strong>. <\/strong>A bitwise shift operator shifts the bits of a binary number to the right by a specified number of positions. The right shift operation effectively divides the original number by 2 raised to the power of the shift count.<\/p>\n<p style=\"text-align: justify;\">For example, if you have a variable x and you want to right shift its bits by 2 positions, you can use the syntax:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nresult=$((x &gt;&gt; 2))<\/code><\/pre>\n<p style=\"text-align: justify;\">This operation will shift the bits of x two positions to the right, resulting in a division of x by 2 raised to the power of 2. The variable result stores the outcome. In Bash scripting, the right shift operator is a common choice for bitwise operations and numerical optimizations.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_the_left_shift_multiply_by_2\"><\/span>Does the left shift multiply by 2?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Yes, the <strong>left shift operation (&lt;&lt;)<\/strong> effectively multiplies a number by 2 raised to the power of the specified shift count. When you left shift a binary number by one position, it is equivalent to multiplying the decimal value by 2. If you left shift by two positions, it is equivalent to multiplying by 2 raised to the power of 2 (2^2), and so on. Therefore, left shifting by &#8216;n&#8217; positions is equivalent to multiplying the number by <strong>2^n<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_you_divide_by_4_in_bit_shift\"><\/span>How do you divide by 4 in bit shift?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To divide a number by 4 using bitwise shift operations, you perform a right shift by 2 positions. In binary representation, a right shift by 2 is equivalent to dividing by <strong>2^2<\/strong> (which is 4 in decimal). So, if you have a variable x, the operation <strong>x &gt;&gt; 2<\/strong> will result in x being divided by 4.<\/p>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/and\/\" target=\"_blank\" rel=\"noopener\">How to Use Bitwise &#8220;AND&#8221; Operator in Bash Script [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/or\/\" target=\"_blank\" rel=\"noopener\">How to Use Bitwise &#8220;OR&#8221; Operator in Bash? [3 Different Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/xor\/\" target=\"_blank\" rel=\"noopener\">&#8220;XOR&#8221; Operator in Bash Scripting [3 Examples]<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bitwise Operators in Bash Scripting&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/\" target=\"_blank\" rel=\"noopener\">Bitwise Operators in Bash Scripting<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Operator&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/\" target=\"_blank\" rel=\"noopener\">Bash Operator<\/a><\/span> | <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/strong><\/p>\n<p style=\"text-align: justify;\">\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"What is << in bitwise?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"In bitwise operations, << is the left bitwise shift operator. It shifts the bits of a binary number to the left by a specified number of positions. The operation is equivalent to multiplying the original number by 2 raised to the power of the shift count.\n\nFor example, if you have the binary number 1010 and perform a left shift by 2 (1010 << 2), the result will be 101000, as each bit is shifted two positions to the left, effectively multiplying the original decimal value by 4.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How to do bitwise shift?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Bitwise shift in Bash is performed using the << (left shift) and >> (right shift) operators. The << operator shifts the bits of a number to the left, effectively multiplying the number by 2 raised to the specified power. Similarly, the >> operator shifts the bits to the right, resulting in division by 2 raised to the specified power. For example, in the expression a << b, the bits in the binary representation of a are shifted to the left by b positions, and in a >> b, the bits are shifted to the right by b positions.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is the right shift operator in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The right shift operator (>>) is one type of bitwise operator in the bash script. A bitwise shift operator shifts the bits of a binary number to the right by a specified number of positions. The right shift operation effectively divides the original number by 2 raised to the power of the shift count.<\/p>\n<p>For example, if you have a variable x and you want to right shift its bits by 2 positions, you can use the syntax:<\/p>\n<p>#!\/bin\/bash\nresult=$((x >> 2))<\/p>\n<p>This operation will shift the bits of x two positions to the right, resulting in a division of x by 2 raised to the power of 2. The result is stored in the variable result. The right shift operator is commonly used in bitwise operations and numerical optimizations in Bash scripting.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Does the left shift multiply by 2?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes, the left shift operation (<<) effectively multiplies a number by 2 raised to the power of the specified shift count. When you left shift a binary number by one position, it is equivalent to multiplying the decimal value by 2. If you left shift by two positions, it is equivalent to multiplying by 2 raised to the power of 2 (2^2), and so on. Therefore, left shifting by 'n' positions is equivalent to multiplying the number by 2^n.\" } },{ \"@type\": \"Question\", \"name\": \"How do you divide by 4 in bit shift?\", \"acceptedAnswer\": { \"@type\": \"Answer\", \"text\": \"To divide a number by 4 using bitwise shift operations, you perform a right shift by 2 positions. In binary representation, a right shift by 2 is equivalent to dividing by 2^2 (which is 4 in decimal). So, if you have a variable x, the operation x >> 2 will result in x being divided by 4.\"\n    }\n  }]\n}\n<\/script><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;29426&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Bitwise Shift Operator in Bash Script [3 Examples]&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>The bitwise shift operators (&lt;&lt; and &gt;&gt;) in Bash manipulate data at the binary level. They are commonly used in &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Bitwise Shift Operator in Bash Script [3 Examples]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#more-29426\" aria-label=\"Read more about Bitwise Shift Operator in Bash Script [3 Examples]\">Read more<\/a><\/p>\n","protected":false},"author":314906,"featured_media":29428,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[173],"class_list":["post-29426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bitwise-operators","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bitwise Shift Operator in Bash Script [3 Examples] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Bash bitwise shift (&lt;&lt; and &gt;&gt;) are efficient for binary operations. Left shift multiplies by 2, and right shift divides by 2.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bitwise Shift Operator in Bash Script [3 Examples] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Bash bitwise shift (&lt;&lt; and &gt;&gt;) are efficient for binary operations. Left shift multiplies by 2, and right shift divides by 2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/msmshah.miran\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-04T06:22:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-13T03:57:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/bash-bitwise-shift.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Mohammad Shah Miran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohammad Shah Miran\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/\"},\"author\":{\"name\":\"Mohammad Shah Miran\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/3d367dace727c53f2b8683eeb23fae77\"},\"headline\":\"Bitwise Shift Operator in Bash Script [3 Examples]\",\"datePublished\":\"2023-12-04T06:22:41+00:00\",\"dateModified\":\"2023-12-13T03:57:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/\"},\"wordCount\":1654,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/bash-bitwise-shift.png\",\"keywords\":[\"bitwise operators\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/\",\"name\":\"Bitwise Shift Operator in Bash Script [3 Examples] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/bash-bitwise-shift.png\",\"datePublished\":\"2023-12-04T06:22:41+00:00\",\"dateModified\":\"2023-12-13T03:57:31+00:00\",\"description\":\"Bash bitwise shift (&lt;< and >>) are efficient for binary operations. Left shift multiplies by 2, and right shift divides by 2.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/bash-bitwise-shift.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/bash-bitwise-shift.png\",\"width\":400,\"height\":400,\"caption\":\"bash bitwise shift\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/shift\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash Operator\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Bitwise Operators in Bash Scripting\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/bitwise-operators\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Bitwise Shift Operator in Bash Script [3 Examples]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/3d367dace727c53f2b8683eeb23fae77\",\"name\":\"Mohammad Shah Miran\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"caption\":\"Mohammad Shah Miran\"},\"description\":\"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/msmshah.miran\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/shah-miran-2a94a7144\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/miran\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bitwise Shift Operator in Bash Script [3 Examples] - LinuxSimply","description":"Bash bitwise shift (&lt;< and >>) are efficient for binary operations. Left shift multiplies by 2, and right shift divides by 2.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/","og_locale":"en_US","og_type":"article","og_title":"Bitwise Shift Operator in Bash Script [3 Examples] - LinuxSimply","og_description":"Bash bitwise shift (&lt;< and >>) are efficient for binary operations. Left shift multiplies by 2, and right shift divides by 2.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/msmshah.miran\/","article_published_time":"2023-12-04T06:22:41+00:00","article_modified_time":"2023-12-13T03:57:31+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/bash-bitwise-shift.png","type":"image\/png"}],"author":"Mohammad Shah Miran","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mohammad Shah Miran","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/"},"author":{"name":"Mohammad Shah Miran","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/3d367dace727c53f2b8683eeb23fae77"},"headline":"Bitwise Shift Operator in Bash Script [3 Examples]","datePublished":"2023-12-04T06:22:41+00:00","dateModified":"2023-12-13T03:57:31+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/"},"wordCount":1654,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/bash-bitwise-shift.png","keywords":["bitwise operators"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/","name":"Bitwise Shift Operator in Bash Script [3 Examples] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/bash-bitwise-shift.png","datePublished":"2023-12-04T06:22:41+00:00","dateModified":"2023-12-13T03:57:31+00:00","description":"Bash bitwise shift (&lt;< and >>) are efficient for binary operations. Left shift multiplies by 2, and right shift divides by 2.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/bash-bitwise-shift.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/12\/bash-bitwise-shift.png","width":400,"height":400,"caption":"bash bitwise shift"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/shift\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash Operator","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/"},{"@type":"ListItem","position":4,"name":"Bitwise Operators in Bash Scripting","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/bitwise-operators\/"},{"@type":"ListItem","position":5,"name":"Bitwise Shift Operator in Bash Script [3 Examples]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/3d367dace727c53f2b8683eeb23fae77","name":"Mohammad Shah Miran","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","caption":"Mohammad Shah Miran"},"description":"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.","sameAs":["https:\/\/www.facebook.com\/msmshah.miran\/","https:\/\/www.linkedin.com\/in\/shah-miran-2a94a7144\/"],"url":"https:\/\/linuxsimply.com\/author\/miran\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/29426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314906"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=29426"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/29426\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/29428"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=29426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=29426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=29426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}