how to use bitwise or operator in /bin/sh

please any one can suggest me how to use bitesie || opearator to do this

#initallize a=0 b=0
#condition
if [ $? -ne 0 ]then
	a=0
else	a=1		
fi
#bitwise or opeartion b = a || b

Bitwise or operation-

Bit_or () {
a=0
b=0
if [[ `expr "$a" + "$b"` > 0 ]]
then
echo "1";
else
echo "0";
fi
}

Bitwise and operation-

Bit_and () {
a=1
b=1
if [[ `expr "$a" \* "$b"` > 0 ]]
then
echo "1";
else
echo "0";
fi
}
1 Like

|| is a logical-OR, not a bitwise-OR (in both sh and C).

Regards,
Alister

Plain sh does not have bitwise operators.

BASH does, though.

$ echo $((1|2|4|8|16|32|64|128))

255

$ echo $((0^0))

0

$ echo $((0^1))

1

$ echo $((1^0))

1

$ echo $((1^1))

0

$ echo ((1<<4))

16

$ echo $((255 & 7))

7

$

etc.