Computing CRC-CCITT (0xFFFF)

basically miscellaneous, if it doesn't fit another sub-forum enter it here, we might even promote it to its own sub-forum
Post Reply
hyte
Posts: 7
Joined: Mon Dec 31, 2012 3:09 am

Computing CRC-CCITT (0xFFFF)

Post by hyte »

I have written a quick script in basic to create a XOR checksum but now I'm working on CRC-CCITT

http://en.wikipedia.org/wiki/Computation_of_CRC
http://www.lammertbies.nl/comm/info/crc ... ation.html

If I could address individual bits I'd be on my way. Is there any way to do this?

At the moment I'm defining variables as BYTE as doing LOTS of XOR and manually checking bytes, doing >> and adding 128

Has anyone implemented CRC-CCITT (0xFFFF) before? I'm not sure I'm going down the correct avenue.



basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Computing CRC-CCITT (0xFFFF)

Post by basicchip »

C and BASIC manipulate bits pretty much the same way. Mask a bit with & (C) AND (BASIC) with a hex value x AND (1<<5) chooses bit 5. Or you could write x AND 0x20

You could write functions to do it, but that would slow you down.

There are lots of examples of calculating different CRC and it should be fairly easy to move them over to BASIC.

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Computing CRC-CCITT (0xFFFF)

Post by basicchip »

You could always create a macro to do bit set, clear or test -- I'm just so use to seeing the AND (1<<x) in code

Code: Select all

#define BITSET(x,bit)        (x  OR (1<<bit))
#define BITCLEAR(x,bit)      (x AND NOT(1<<bit))
#define TESTBIT(x,bit)       (x AND (1<<bit))
 

hyte
Posts: 7
Joined: Mon Dec 31, 2012 3:09 am

Re: Computing CRC-CCITT (0xFFFF)

Post by hyte »

That clear thing up. Now to port and post the function. Cheers

Post Reply