Excellent questions! BSET takes two values. The first is the number to be changed, and the second one is the bit of the first number that is to be set to 1. So, for example, BSET 2 3 takes the number 2 (binary: 10), and sets its third bit to change it into 6 (binary: 110). So, the reason the first number is 0 is because we want all the other bits to be 0 (other than the one being set).
Turning to your second question… The line in the loop is a bit cunning :-).
L 0 11: K ? BGET J I I K
I needed a loop that counted through the binary number bit by bit until it found the one that was set to 1. Normally we’d do that with a while loop or something, or a loop that would break out when it found a 1, but you can’t do that with the teletype language syntax because you can only have one statement inside the loop. So, this line goes through every bit in J. We want K to end up being the index of the “hot” bit in J. We start with K equal to zero. If the current bit in J that we’re looking at is 1 then we want to set K to the loop counter (that is, I) otherwise we leave K alone. (So, if we haven’t hit the right bit yet, K will be zero, if it’s after the right bit, K will stay at that index number.) So, let’s unpack that line…
The ? operator is a so-called “ternary if” statement. The first part is the condition part: “BGET J I”. If that is 1, this operator returns the next part “I”. If it is 0, then it returns the third part “K”. The result of this ternary if is what updates the value of K. (This would all be unnecessary if we had log base two in Teletype
)
Phew… hope this makes sense! Sorry for going on a bit about such a wee piece of code 