回复 60楼 shuxin211
粗粗看了一下,对照测试了一下。B B B B B B B B B B B B B B B B B B B B B B B B B B B
B B P B B P B B P B B P B B P B B P B B P B B P B B P
B P B B P B B P B B P B B P B B P B B P B B P B B P B
B P P B P P B P P B P P B P P B P P B P P B P P B P P
P B B P B B P B B P B B P B B P B B P B B P B B P B B
P B P P B P P B P P B P P B P P B P P B P P B P P B P
P P B P P B P P B P P B P P B P P B P P B P P B P P B
P P P P P P P P P P P P P P P P P P P P P P P P P P P
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 ... 19173961
0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 ... 38347922
0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 ... 57521883
1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 ... 76695844
1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 ... 95869805
1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 ... 115043766
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... 134217727
先将提供的BP表(27位)转换成二进制和10进制数值,作测试对照参考。
只显示结果:
程序代码:
CLEAR SET TALK OFF CREATE CURSOR bpb (bpn I, bp1 I, bp2 I, bpi I) INSERT INTO bpb VALUES ( 0, 0, 0, 1) INSERT INTO bpb VALUES ( 19173961, 0, 0, 1) INSERT INTO bpb VALUES ( 38347922, 0, 0, 1) INSERT INTO bpb VALUES ( 57521883, 0, 0, 1) INSERT INTO bpb VALUES ( 76695844, 0, 0, 1) INSERT INTO bpb VALUES ( 95869805, 0, 0, 1) INSERT INTO bpb VALUES (115043766, 0, 0, 1) INSERT INTO bpb VALUES (134217727, 0, 0, 1) nBits = 27 nBPk = 0 n位数 = 3 DO WHILE .T. nRet = MESSAGEBOX("P...是"+0h0D+"B...否", 3+32+512, "提示") IF nRet == 2 EXIT ENDIF nBP = IIF(nRet == 6, 1, 0) nBPk = nBPk + 1 nBit = MOD(nBPk, n位数) nBit = IIF(nBit == 0, n位数, nBit) CLEAR 建BP表(nBits) ? ? " nBP="+IIF(nBP==0,"B","P"), " nBPk="+TRANSFORM(nBPk), " nBit="+TRANSFORM(nBit) ? ? " BP BPi BP2 BPi+1" nB = 0 nP = 0 SELECT bpb SCAN REPLACE bpb.bp1 WITH 取bp(bpb.bpn, nBit, nBits),; bpb.bp2 WITH 取bp(bpb.bpn, nBPk+1, nBits) ? " " + IIF(bpb.bp1==0, "B", IIF(bpb.bp1==1, "P", "-")) ?? bpb.bpi ?? " "+IIF(bpb.bp2==0, "B", IIF(bpb.bp2==1, "P", "-")) ?? bpb.bpi + IIF(bpb.bp1 == nBP, -1, 1) REPLACE bpb.bpi WITH bpb.bpi + IIF(bpb.bp1 == nBP, -1, 1) nB = nB + IIF(bpb.bp2 == 0, bpb.bpi, 0) nP = nP + IIF(bpb.bp2 == 1, bpb.bpi, 0) ENDSCAN ? ? " B="+TRANSFORM(nB), " P="+TRANSFORM(nP) ENDDO RETURN FUNCTION 取bp(bpn, nBit, nBits) IF !BETWEEN(bpn, 0x00000000, 0xFFFFFFFF) OR !BETWEEN(nBit, 1, nBits) RETURN -1 ENDIF RETURN BITRSHIFT(BITLSHIFT(bpn, 32 - nBits + nBit - 1), 31) ENDFUNC FUNCTION 建BP表(nBits) LOCAL i, nBP SELECT bpb SCAN ? bpb.bpn, "..." FOR i = 0 TO nBits-1 nBP = BITRSHIFT(BITLSHIFT(bpb.bpn, 32 - nBits + i), 31) ?? " " + IIF(nBP==0, "B", "P") ENDFOR ENDSCAN ENDFUNC