3 filename="${1:-p2_208.txt}"
10 local value=${line#* = }
15 if [ $key == "mask" ]; then
18 # it's a memory instruction, yay
21 base_mask=$(get_base_mask $cur_mask $loc)
24 for mask in "${masks[@]}"; do
25 loc=$(get_value $mask $loc)
36 # here we literally translate the string to contain X if
37 # it's an X, and then check against the value and if either
38 # value or mask has a 1 in that position set it to 1 other
40 for (( a=0; a<36; a++ )); do
41 if [ ${mask:$a:1} == "X" ]; then
43 elif [ ${mask:$a:1} -eq 1 ] || [ $((value & 2**(35-$a))) -gt 0 ]; then
55 local test="${string/X/b}"
60 if [ "$string" == "$test" ]; then
65 # do the 2 potential replacements and run them through
75 local mask_part1=${mask//X/0}
76 local mask_part2=${mask//1/X}
77 mask_part2=${mask_part2//0/1}
78 mask_part2=${mask_part2//X/0}
79 value=$((value | 2#$mask_part1))
80 value=$(( ~ $value & (2**36)-1 ))
81 value=$((value | 2#$mask_part2))
82 value=$(( ~ $value & (2**36)-1 ))
87 while read -u 3 line; do
92 for key in ${!mem[@]}; do
93 total=$((total+${mem[$key]}))