Print Bin$(SgnX(7,&h7f),64)
0000000000000000000000000000000000000000000000000000000001111111 ^ bit 7
Print Bin$(SgnX(7,&h8f),64)
1111111111111111111111111111111111111111111111111111111110001111 ^ bit 7
RTC GetReg 17,x
Print Bin$(x,64)0000000000000000000000000000000000000000000000000000000011111110
x=SgnX(7,x)Print Bin$(x,64)1111111111111111111111111111111111111111111111111111111111111110Print x-2
Function SgnX(b As Integer,v As Integer) As Integer' sign extend bit b of value v If v And 2^b Then 'extend 1 SgnX=v Or (-1 << (b+1)) Else 'extend 0 SgnX= v And ((2^(b+1))-1) EndIf End Function