karinha wrote:
- Code: Select all Expand view RUN
// C:\FWH\SAMPLES\CRC.PRG
#include "fivewin.ch"
// #include "HbCompat.ch"
MEMVAR aCrc, poly, initvalue, finavalue
FUNCTION Main()
LOCAL crcResu, CCRCRESU, cResult
PRIVATE aCrc := { 0x00, 0x01, 0x07 }
PRIVATE poly := 0x8005
PRIVATE initvalue := 0xFFFF
PRIVATE finavalue := 0x0000
Ccrcresu := Calculate_Crc()
// asi, funciona:
? HB_NumToHex( Ccrcresu )
? HB_NumToHex( hb_Random( 0xFFFFFF ) ) + '"'
// no funciona:
// cResult := hb_NumToHex( crcresu, 4 ) // return error.
// ? cResult
// xHarbour:
// cResult := NumToHex( crcresu, 4 )
RETURN NIL
FUNCTION Calculate_Crc()
LOCAL crc := initvalue, i, j
FOR I = 1 TO Len( aCrc )
crc = hb_bitXor( crc, hb_bitShift( aCrc[ i ], 8 ) )
FOR j = 1 TO 8
IF hb_bitAnd( crc, 0x8000 ) <> 0
crc = hb_bitXor( hb_bitShift( crc, 1 ), poly )
ELSE
crc = hb_bitShift( crc, 1 )
ENDIF
NEXT
NEXT
RETURN hb_bitXor( crc, finavalue )
/*
hbmisc.hbc
DecToHexa()
HexaToDec()
IsHexa()
hbnf.hbc (instalado):
ft_Byt2Hex()
ft_Hex2Dec()
xhb.hbc
HexToNum()
HexToStr()
NumToHex()
StrToHex()
Harbour Core ***
hb_HexToNum()
hb_HexToStr()
hb_NumToHex()
hb_StrToHex()
hbmisc.hbc
BinToDec()
DecToBin()
IsBin()
hbnf.hbc
ft_Dec2Bin()
Harbour Core *** Return -> Int <- Param
Bin2I()
Bin2L()
Bin2W()
I2Bin()
L2Bin()
*/
// FIN / END
Regards, Saludos.
Thanks a lot. Share these solution functions