LINUX.ORG.RU

История изменений

Исправление futurama, (текущая версия) :

x=6144 #b1100000000000
m=2047 #  b11111111111
while read Line; do
  num=$((2#$Line))
  if [[ "$num" -ge $x ]]; then
    num=$(($num-$x))
    echo "-"$(( $num ^ $m ))
  else
    echo $((2#${Line:2:14}))
  fi
done <file.txt

Результат

$ time ./aaa.sh | wc -l
500000

real	0m6.444s
user	0m5.619s
sys	0m2.023s

Исправление futurama, :

x=6144 #b1100000000000
m=2047 #  b11111111111
while read Line; do
  num=$((2#$Line))
  if [[ "$num" -ge $x ]]; then
    num=$(($num-$x))
    echo "-"$(( $num ^ $m ))
  else
    echo $((2#${Line:2:14}))
  fi
done <file.txt

Исправление futurama, :

x=6144 #b1100000000000
m=2047 #  b11111111111
while read Line; do
  num=$((2#$Line))
  if [[ "$num" -ge $x ]]; then
    num=$(($num-$x)
    echo "-"$(( $num ^ $m ))
  else
    echo $((2#${Line:2:14}))
  fi
done <file.txt

Исправление futurama, :

# 12288 = b11000000000000
while read Line; do
  num=$((2#$Line))
  if [[ "$num" -ge 12288 ]]; then
    num=$(($num-12288)
    echo "-"$(( $num ^ 4095 ))
  else
    echo $((2#${Line:2:14}))
  fi
done <file.txt

Исправление futurama, :

# 12288 = b11000000000000
while read Line; do
  num=$((2#$Line))
  if [[ "$num" -ge 12288 ]]; then
    num=$(($num-12288)
    echo $(( $num ^ 4095 ))
  else
    echo $((2#${Line:2:14}))
  fi
done <file.txt

Исправление futurama, :

# 12288 = b11000000000000
while read Line; do
  num=$((2#$Line))
  if [[ "$num" -ge 12288 ]]; then
    awk '{print xor($1-12288, 4095)}' <<<$num
  else
    echo $((2#${Line:2:14}))
  fi
done <file.txt

Исходная версия futurama, :

# 12288 = b11000000000000
while read Line; do
  Line=$((2#$Line))
  if [[ "$Line" -ge 12288 ]]; then
    awk '{print xor($1-12288, 4095)}' <<<$Line
  else
    echo $Line
  fi
done <file.txt