Hola
Existe el operador Unario (Unary, ~ operador) en Harbour?
O alguien lo tiene construido desde un valor decimal o hexadecimal?
Function OperUnary( nNum )
Local nVal
Local cVal := ""
Local nLen := hb_BLen( DecToBin( nNum ) )
Local x
Local cNumBin := DecToBin( nNum )
// ? Valtype( DecToBin( 10 ) )
// ? HB_BITNOT( 5 ) // -6
For x = 1 to nLen
if Substr( cNumBin, x , 1 ) = "1"
cVal := cVal + "0"
else
cVal := cVal + "1"
endif
Next x
nVal := BinToDec( cVal )
//? cNumBin, nVal, cVal
Return nVal
#pragma BEGINDUMP
#include <hbapi.h>
#include <math.h>
HB_FUNC( C_COMPLEMENT )
{
long long int nDecimal1;
long long int nComplement;
nDecimal1 = hb_parnll(1);
nComplement = ~nDecimal1;
hb_retnll( nComplement );
}
#pragma ENDDUMP
? hb_bitNot(5000)
FUNCTION HexToBinary(cHex)
LOCAL nLenBin, nX, nPos, cBinNumber, cCharHex, cBinBase
aHexBinary := { {"0", "0000"}, {"1", "0001"}, {"2", "0010"}, {"3", "0011"}, {"4", "0100"}, {"5", "0101"},;
{"6", "0110"}, {"7", "0111"}, {"8", "1000"}, {"9", "1001"}, {"A", "1010"}, {"B", "1011"},;
{"C", "1100"}, {"D", "1101"}, {"E", "1110"}, {"F", "1111"}}
cBinNumber := ""
cHex := alltrim(cHex)
FOR nX := len(cHex) TO 1 STEP -1
cCharHex := substr(cHex, -nX, 1)
nPos := ascan(aHexBinary, { |a| a[1] == substr(cHex, -nX, 1)} )
cBinBase := aHexBinary[nPos,2]
cBinNumber := cBinNumber + cBinBase
NEXT
RETURN (cBinNumber)
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 25 guests