Tuesday 15 September 2015

bash - Efficient way to bit mask every number of a file list using bitwise operators -


I have a file that has a list of numbers defined as follow:

  Var1 = 0x0000002 var2 = 0x00000008 var4 = 0x00000040 var6 = 0x00000080 var7 = 0x00000000 var9 = 0x00000400 var10 = 0x00000800 var11 = 0x000001000 var12 = 0x000002000 var13 = 0x000004000 var14 = 0x000008000 var15 = 0x00010000 var16 = 0x00020000 var17 = 0x00040000 var18 = 0x10000000 var19 = 0x40000000 var20 = 0x80000000 var21 = 0x80000000  

I have to type something like this:

  decValue = 2147483650 printf -v hexview "% X" $$ {DecValue} "resonate $ hexValue IFS =" = "While testing the name ID $$ ($ {hexvalue} and $ {id})) = 0 & amp; array + = Continue ("$ {name}") & lt; "$ FILE_NAME"  < / Pre> 

It gives:

  80000002 var2 var9 var11 var12 var14 var17  

However, in this particular case I would just like to return Other examples, if decValue = 12288 I would like to return to var11 and var12:

  var21 var2  

Is bits operators a good tool to solve this problem?

use

  printf -v hexValue "% # x" Use the "$ {decValue}"  

(or $ {decimalValue} test inside the loop)

< P> As it is now, ending $ hexValue 80000002 (as it shows your own echo statement), and after In it, it is defined as a decimal number when you want to interpret it as hexadeximal one.

Passing % # x as printf to the format specifier $ hexValue value 0x80000002 Will be.

You should take another good look at the var table; There are several intervals between var3 and var3 between 0x4 is unavailable; var3 between 0x10 is unavailable and between var4 , and var17 and var18 , from 0x80000 to 0x8000000 < / Code> has gone well as a whole block, you are not getting the expected results for any of these beat sets.

This can also be thought to generate bitmasks on the fly because they are not kept in the file correctly. For a possible approach

  for ((i = 0; (1 < 

In this, the bitspace expression 1 & lt; & Lt; I give number 2 i , or in some other way: 1 < & Lt; There is a similar value as << Code> var $ ((i + 1)) .


No comments:

Post a Comment