FWH or harbour function support CRC? ( Solved )

FWH or harbour function support CRC? ( Solved )

Postby richard-service » Wed Jan 10, 2024 10:38 am

Hi

FWH or Harbour any CRC function?
I have some data below:
    CRC WIDTH : CRC-16
    Polynomial : 0x8005
    Initial Value : 0xFFFF
    Final Xor Value: 0x0000

input this 000107 -> CRC RESULT 0x8811
Last edited by richard-service on Tue Jan 23, 2024 8:23 am, edited 1 time in total.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: FWH or harbour function support CRC?

Postby Natter » Wed Jan 10, 2024 11:45 am

nStrCRC(mystr)
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: FWH or harbour function support CRC?

Postby richard-service » Thu Jan 11, 2024 5:14 am

Natter wrote:nStrCRC(mystr)


Yes, I try it. But not work.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: FWH or harbour function support CRC?

Postby Antonio Linares » Thu Jan 11, 2024 9:59 am

? hb_CStr( hb_SHA256( hb_memoRead( "filename.zip" ), nil ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: FWH or harbour function support CRC?

Postby nageswaragunupudi » Fri Jan 12, 2024 6:16 am

I tried this way but I am getting a different result.
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local n

   ? n := CRC_16( "000107" )
   ? NUMTOHEX( n )   // "FF3A"

return nil

#pragma BEGINDUMP

#include <hbapi.h>

unsigned int crc16(unsigned char *data, unsigned int data_length ) {
    unsigned int crc = 0xFFFF;
    unsigned int polynomial = 0x8005;
    unsigned int i, j;

    for (  i = 0; i < data_length; i++) {
        crc ^= data[i];
        for ( j = 0; j < 8; j++) {
            crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
        }
    }
    return crc;
}

HB_FUNC( CRC_16 )
{
   hb_retni( crc16( hb_parc( 1 ), hb_parclen( 1 ) ) );
}

#pragma ENDDUMP
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FWH or harbour function support CRC?

Postby richard-service » Fri Jan 12, 2024 6:42 am

Antonio Linares wrote:? hb_CStr( hb_SHA256( hb_memoRead( "filename.zip" ), nil ) )


Dear Antonio,

It's not work.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: FWH or harbour function support CRC?

Postby richard-service » Fri Jan 12, 2024 6:44 am

nageswaragunupudi wrote:I tried this way but I am getting a different result.
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local n

   ? n := CRC_16( "000107" )
   ? NUMTOHEX( n )   // "FF3A"

return nil

#pragma BEGINDUMP

#include <hbapi.h>

unsigned int crc16(unsigned char *data, unsigned int data_length ) {
    unsigned int crc = 0xFFFF;
    unsigned int polynomial = 0x8005;
    unsigned int i, j;

    for (  i = 0; i < data_length; i++) {
        crc ^= data[i];
        for ( j = 0; j < 8; j++) {
            crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
        }
    }
    return crc;
}

HB_FUNC( CRC_16 )
{
   hb_retni( crc16( hb_parc( 1 ), hb_parclen( 1 ) ) );
}

#pragma ENDDUMP


Dear Mr.Rao

Return value not work.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: FWH or harbour function support CRC?

Postby richard-service » Fri Jan 12, 2024 6:48 am

Dear Antonio, Mr.Rao, Natter

Right value => 0x8811

I show some test tools below:
Image
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: FWH or harbour function support CRC?

Postby karinha » Fri Jan 12, 2024 2:35 pm

Code: Select all  Expand view

C:\HBBCC74\src\rtl

03/04/2020  19:58            12.184 hbcrc.c

C:\XHBBCC74\contrib\unicode

25/02/2020  13:19             6.613 hbcrc16.c
25/02/2020  13:19             8.003 hbcrc32.c
               2 arquivo(s)         14.616 bytes

C:\XHBBCC74\source\rtl

25/02/2020  13:20             3.116 hbcrc32.c
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: FWH or harbour function support CRC?

Postby richard-service » Tue Jan 16, 2024 9:49 am

karinha wrote:
Code: Select all  Expand view

C:\HBBCC74\src\rtl

03/04/2020  19:58            12.184 hbcrc.c

C:\XHBBCC74\contrib\unicode

25/02/2020  13:19             6.613 hbcrc16.c
25/02/2020  13:19             8.003 hbcrc32.c
               2 arquivo(s)         14.616 bytes

C:\XHBBCC74\source\rtl

25/02/2020  13:20             3.116 hbcrc32.c
 


Regards, Saludos.


Dear Karinha,

not work.
I have VS code from device. Could you test it?
If yes, please send to me or show Email.
Thank you.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan


Re: FWH or harbour function support CRC?

Postby richard-service » Thu Jan 18, 2024 2:36 am

Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: FWH or harbour function support CRC? ( Solved )

Postby richard-service » Tue Jan 23, 2024 8:24 am

Dear All,

FWH or harbour CRC function not work. Very strange.
so I make these code and solved my problem below:

Code: Select all  Expand view

#include "fivewin.ch"

MEMVAR aCrc
MEMVAR poly
MEMVAR initvalue
MEMVAR finavalue

FUNCTION MAIN()
LOCAL crcResu
PRIVATE aCrc:={0x00,0x01,0x07}
PRIVATE poly:=0x8005
PRIVATE initvalue:=0xFFFF
PRIVATE finavalue:=0x0000
Ccrcresu:=Calculate_Crc()
aa=hb_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)
 
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: FWH or harbour function support CRC? ( Solved )

Postby karinha » Tue Jan 23, 2024 2:20 pm

Code: Select all  Expand view

// 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: FWH or harbour function support CRC? ( Solved )

Postby nageswaragunupudi » Tue Jan 23, 2024 3:17 pm

so I make these code and solved my problem below:

Congratulations and thanks for sharing your solution.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests