[HN Gopher] Rediscovering Hamming Code
___________________________________________________________________
Rediscovering Hamming Code
Author : juxhindb
Score : 25 points
Date : 2021-04-18 11:55 UTC (11 hours ago)
(HTM) web link (blog.digital-horror.com)
(TXT) w3m dump (blog.digital-horror.com)
| anonymousiam wrote:
| Re: "fast" parity code in article. I always preferred the parity
| example from the (pre-ansi) K&R C Programming Language book:
|
| #include <stdio.h>
|
| main( argc, argv ) int argc; char *argv[];
|
| { unsigned source; int parity;
| if ( argc > 1 ) { if ( sscanf( argv[1], "%d",
| &source ) == 1 ) { printf( "%d = ",
| source ); for ( parity = 0; source; parity++ )
| source &= ( source - 1 ); printf( "%d\n", parity
| & 1 ); } }
|
| }
|
| The function in the article is faster for > 8-bit values when
| there are more than eight ones in the value being checked. Also,
| I suppose theirs is better than K&R because it always executes in
| the same number of cycles.
___________________________________________________________________
(page generated 2021-04-18 23:02 UTC)