#!/bin/bash
# Bit-Operatoren in Bash
# Bitweises UND (AND)
a=5 # Binär: 0101
b=3 # Binär: 0011
result=$((a & b)) # Binär: 0001 (dezimal: 1)
echo "Bitweises UND: $result"
# Bitweises ODER (OR)
a=5 # Binär: 0101
b=3 # Binär: 0011
result=$((a | b) # Binär: 0111 (dezimal: 7)
echo "Bitweises ODER: $result"
# Bitweises XOR (Exklusives ODER)
a=5 # Binär: 0101
b=3 # Binär: 0011
result=$((a ^ b)) # Binär: 0110 (dezimal: 6)
echo "Bitweises XOR: $result"
# Bitweises NOT (Negation)
a=5 # Binär: 0101
result=$((~a)) # Binär: 1010 (dezimal: -6)
echo "Bitweises NOT: $result"
# Linksverschiebung (Shift nach links)
a=5 # Binär: 0101
result=$((a << 2)) # Binär: 10100 (dezimal: 20)
echo "Linksverschiebung: $result"
# Rechtsverschiebung (Shift nach rechts)
a=5 # Binär: 0101
result=$((a >> 1)) # Binär: 0010 (dezimal: 2)
echo "Rechtsverschiebung: $result"