I have a file which contains a list of numbers defined as follow :
var1=0x00000001
var2=0x00000002
var3=0x00000008
var4=0x00000020
var5=0x00000040
var6=0x00000080
var7=0x00000100
var8=0x00000200
var9=0x00000400
var10=0x00000800
var11=0x000001000
var12=0x000002000
var13=0x000004000
var14=0x000008000
var15=0x00010000
var16=0x00020000
var17=0x00040000
var18=0x10000000
var19=0x20000000
var20=0x40000000
var21=0x80000000
I want to write something like this:
decValue=2147483650
printf -v hexValue "%x" "${decValue}"
echo $hexValue
IFS="="
while read name ID x
do
test $((${hexValue} & ${ID})) = 0 && continue
array+=("${name}")
done < "$FILE_NAME"
It returns :
80000002
var2 var9 var11 var12 var14 var17
But, in this specific case I just would like to return :
var21 var2
Other example, if decValue=12288 I would like to return var11 and var12.
Bitwise operators is a good tool to solve this issue ?