Hello All,
i have two 16 bit binaries that in two different variables, i want to perform a bitwise AND between the two and store the result in a different variable.
can anyone throw some light on doing this in a bourne shell...
eg var1= 1110101010101011
bit wise and with var2= 1111111111111110
----------------------
result = 1110101010101010
You cannot use bourne shell alone to do that. bash has bitwise operators as builtins.
You will have to resort to another interpreted language like perl, or a compiled language like C, if you cannot switch to bash at all.
c example:
Last edited by jim mcnamara; 11-28-2011 at 11:44 AM..
This User Gave Thanks to jim mcnamara For This Post:
Alright, so I was curious how to do this in bash, having never myself attempted it. It's a bit tricky.
First, you can do the operation directly using "Arithmetic Expansion", ie $(( ... ))
The "2#" tells bash to interpret the following string as a binary (base-2) number.
Without those, you get:
ie, gibberish.
For variables, it's the same:
You can also tell bash to interpolate x and y as strings and then into binary numbers like this:
See how bash first substitutes $x as a string, then interprets the resulting token into a binary number?
can we compare the value in positions of the variables. For example break the bits and store in individual variables, and do the same with the second variable which is storing the other 16 bits.
ex 1010101010101010
break the value in to 16 variables so that
from right to left
var 0 = 0, var 1 = 1 var 2= 0 etc....till var 15
then
do the same with the second 16 bit binary
xvar 0 = 1 xvar 1 = 1 xvar 2 = 1
compare value
if var 0 = 0 and xvar 0 = 1 then result = 0..... store this in variable yvar 0
if var 1= 0 and xvar 1 = 1 then result = 0......store this in variable yvar 1
if var 2= 1 and xvar 2 = 0 then result = 0 ... store this in variable yvar 2
var [n] xvar[n] yvar[n]
so on till var 15
can anyone throw some light on doing this way.....
Hello,
I want to compute the bitwise number of matches in pairwise fashion for all columns. The problem is I have 18486955 rows and 750 columns. Please help with code, I believe this will take a lot of time, is there a way of tracking progress?
Input
Org1 Org2 Org3
A A T
A ... (9 Replies)
please any one can suggest me how to use bitesie || opearator to do this
#initallize a=0 b=0
#condition
if then
a=0
else a=1
fi
#bitwise or opeartion b = a || b
Please view this code tag video for how to use code tags when posting code and data. (3 Replies)
The purpose of this article is revealing the unrevealed parts of the bitwise XOR.
As we aware, the truth table for the XOR operator is :
A B A^B
0 0 0
0 1 1
1 0 1
1 1 0
For example , 1^2 will be calculated as given below:
First the operands... (1 Reply)
Hi
Suppose we have these code lines:
#define _IN_USE 0x001 /* set when process slot is in use */
#define _EXITING 0x002 /* set when exit is expected */
#define _REFRESHING 0x004
...
1 main () {
2
3 unsigned r_flags =_REFRESHING;
4
5 if (r_flag &... (3 Replies)
I am taking an online course on Unix scripting. The topic is Unix arithmetic operators and the lesson is Logical and bitwise operations. It is not clear how much storage space Unix uses to represent integers that are typed. Bitwise negation caused me to question how many bits are used to... (3 Replies)
Hi,
Is it possible to use bitwise operators in bit fields?
For example:
typedef struct Mystruct {
unsigned char A :1 ;
unsigned char B :1 ;
} Mystruct;
and assume
struct Mystruct STR_1S, STR_2S, tempSTRS = {0};
then the following line:
tempSTRS = STR_1S & STR_2S;
gives the... (3 Replies)