O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The rshift (val, count) function

This function returns the value of  val, shifted to the right side by the count number of bits specified in the argument. 0s are shifted in from the left side. For example, let us right shift the decimal once time to show how the rshift() function works:

5 = 101

rshift once = 010 which is decimal 2

The following example shows how the rshift() functions work:

$ vi rshift.awkBEGIN    {    num1 = 5    count =1     result = rshift(num1,count)    printf "rshift(%d,%d) = %d\n", num1, count, result}$ awk -f rshift.awk

The output of the execution of the previous code is as follows:

rshift(5,1) = 2

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required