Your Own Linux

Tech Blog

  • Home
  • About
  • Blog
  • Technology
  • Business
  • Contact Us

Your Own Linux

August 14, 2022 by Skyler Leave a Comment

The Linux command line can be a powerful tool for quickly running commands, parsing data and making changes to the system. This post will cover some of the basics which will get you up and running with bash. We’ll cover some of the bitshift operators people often use in bash, bitwise operators we come across in bash and arithmetic operations we do with numbers in bash. The most common way of getting around the linux command line is with the bash shell. Bash is a command line interpreter for running commands on the system. Although its part of the broader POSIX standard, most other shells are compatible with bash. The OS will automatically try to run bash if it can’t find another shell during startup.

The Shift Operators

Most people who’ve gone through a programming class will remember < , > & – for shifting values left, right and negative. That’s exactly what bash does with them. In addition to the above shift operators, bash supports additional shift operators. These are often used to manipulate strings that contain special characters.

Unshifted Positional Arguments

Number 0

Argument is bit field of 1s and is intended for use with unary operators (see below). Arithmetic multiplication, division and modulo (remainder) all work as expected on this argument.

Left Shifted Positional Arguments

Numbers 0-65535

Argument can be used as an index into an array: ${arrayname [$1]} where arrayname is the array. The $1 variable is set to the value of the one’s position in the array, i.e. [0] and [-32768] are equivalent. Arithmetic multiplication, division and modulo (remainder) all work as expected on this argument.

Right Shifted Positional Arguments

Numbers 0-65535

Argument can be used as an index into an array: ${arrayname [$1]} where arrayname is the array. The $1 variable is set to the value of the one’s position in the array, i.e. [0] and [-32768] are equivalent. Arithmetic multiplication, division and modulo (remainder) all work as expected on this argument. Bitwise Operators

Bash provides some additional operators which work on bits and bytes. You will most likely want to use these when you want to manipulate or parse data on a smaller level. There are two sets of bitwise operators: regular bitwise operators and and or xor unary operators.

A regular bitwise operator is an arithmetic operator that operates on the bits of a number, for example, the & operator checks if a number is even, which can be encoded as 4 bits in binary. Similarly, the | operator checks if there are left-to-right bitwise complement of a number.

The & and | operators take two arguments, X and Y . To get the bitwise AND (bitwise AND) value of X from Y , first use the & operator to look at the bits in X . Then assign a 1 to each bit that is on and set 0 for all other bits. This will produce a value of 1 for each row where the bits in X are all ones, which is what we want. Finally, use the | operator to check if each column of the output has all ones. If any column has more than one 1, then set all bits that are on to 0, otherwise leave them unchanged.

Conclusion

The bitwise operators are useful when you need to work with smaller chunks of data. As with most things in life, practice will make perfect. You will find yourself using these operators more and more as you get accustomed to bash.

Filed Under: Blog

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

About Us

Hello there! I’m Skyler a professional tech guy you can count on. I’m here to share with you my broad knowledge when it comes to tech stuff. I do some configuring and coding that might be helpful to you. Read More…

Connect With Us

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter

Latest Post

  • Advice For Building Team Culture In Modern Times
  • Is Your Business Infrastructure Up To Date And Is That Important?
  • How can a business degree help in succeeding businesses?
  • Digital Business Solutions You Might Not Be Taking Advantage Of
  • Field Service Reporting: Here is a Complete Guide to Field Service Reporting

NewsLetter

Featured

Advice For Building Team Culture In Modern Times

Is Your Business Infrastructure Up To Date And Is That Important?

Free Startup Meeting photo and picture

How can a business degree help in succeeding businesses?

Digital Business Solutions You Might Not Be Taking Advantage Of

Field Service Reporting: Here is a Complete Guide to Field Service Reporting

Free Woman in Red Sweater Leaning on White Table Stock Photo

5 Top MBA Concentrations to Consider

4 trending MBA specializations you can pursue

Ways To Prepare Cuttlefish

How Jobs To Be Done Helps Businesses and How It Works

Top Software Development Trends of 2023

About Us

Hello there! I’m Skyler a professional tech guy you can count on. I’m here to share with you my broad knowledge when it comes to tech stuff. I do some configuring and coding that might be helpful to you. Read More…

Latest Post

  • Advice For Building Team Culture In Modern Times
  • Is Your Business Infrastructure Up To Date And Is That Important?
  • How can a business degree help in succeeding businesses?
  • Digital Business Solutions You Might Not Be Taking Advantage Of
  • Field Service Reporting: Here is a Complete Guide to Field Service Reporting

NewsLetter

Connect With Us

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter

Copyright © 2023 Your Own Linux