Detect whether a 9-bit candidate mask in BC contains exactly one bit set (a naked single).
Input: BC = 9-bit mask (bits 0–8 used).
Output: A = digit 1–9 if exactly one candidate.
Flags: Z reset if single candidate found; Z set if zero or multiple bits set.
1. Check BC == 0 (contradiction).
2. Perform power-of-two test: x & (x-1) == 0.
3. If single bit, scan to determine bit index and convert to digit.
SingleCandidateFromMask:
; Check for zero mask
LD A,B
OR C
RET Z
; HL = BC
LD HL,0
ADD HL,BC
DEC HL ; HL = BC - 1
; (BC & (BC-1)) test
LD A,B
AND H
LD D,A
LD A,C
AND L
OR D
RET NZ ; multiple bits set
; Determine bit index
LD A,0 ; bit index
ScanLoop:
BIT 0,C
JR NZ,FoundBit
SRL B
RR C
INC A
CP 9
JR NZ,ScanLoop
RET ; safety exit
FoundBit:
INC A ; convert 0–8 → 1–9
OR 1 ; ensure Z flag reset
RET