Omega Races uses a Grey Code encoding.
Doing an alta vista search for "Grey Code" I found these wee converter programs
too (after I decoded the EPROM, of course..)
#include <stdio.h>
int main(int args, unsigned char *argc[]) {
unsigned char num, gnum;
int j, bit,numbits=8;
unsigned int mask ;
if (args!=2) {
printf("Usage: g2bin GreyCodeNumber\n");
return(-1);
}
gnum=(unsigned char) strtoul(argc[1], (char **)NULL, 16);
/* g2bin is for numbers with bits fewer than 8, it works for only for
numbers with 8 or fewer bits because this transformation depends on the number
of bits in the number */
if (gnum > 0xff) {
printf("Number must be smaller than 8 bits\n");
return(-1);
}
/* Calculate the binary code equivalent of the gray number */
num = gnum ^ (gnum >> 0x01) ^ (gnum >> 0x02) ^ (gnum >> 0x03)
^ (gnum >> 0x04) ^ (gnum >> 0x05) ^ (gnum >> 0x06) ^ (gnum >> 0x07);
printf("Decimal binary num is %lu\n", num);
printf("Decimal grey equivalent is %lu\n", gnum);
printf("Grey code number Binary Number\n");
printf(" ");
bitDump(&gnum, &numbits);
printf("\t \t");
bitDump(&num, &numbits);
printf("\n");
return(0);
}
int bitDump(unsigned char *num, int *numbts){
int j;
unsigned long int mask;
int bit;
mask = 0x80;
for (j=0;j<*numbts;j++) {
bit =(mask & *num) ? 1 : 0;
printf("%d", bit);
mask >>=1;
}
return(0);
}
#include <stdio.h>
int main(int args, unsigned char *argc[]) {
unsigned char num, gnum;
int j, bit,numbits=8;
unsigned int mask ;
if (args!=2) {
printf("Usage: bin2g HexBinaryNumber\n");
return(-1);
}
if (args>2) {
printf("Second argument ignored\n");
}
num = (unsigned char ) strtoul(argc[1],(char **)NULL, 16);
/* bin2g is for numbers with bits fewer than 8, it works for any number
of bits, but the g2bin depends on the number of bits, currently, 8 */
if (num > 0xff) {
printf("Number must be smaller than 8 bits\n");
return(-1);
}
/* Calculate the grey code equivalent */
gnum = num ^ (num >> 0x01);
printf("Decimal binary num is %lu\n", num);
printf("Decimal grey equivalent is %lu\n", gnum);
printf("Grey code number Binary Number\n");
printf(" ");
bitDump(&num, &numbits);
printf("\t \t");
bitDump(&gnum, &numbits);
printf("\n");
return(0);
}
/* bitDump function takes the number and the number of bits and prints
the binary equivalent of the number */
int bitDump(unsigned char *num, int *numbts){
int j;
unsigned long int mask;
int bit;
mask = 0x80;
for (j=0;j<*numbts;j++) {
bit =(mask & *num) ? 1 : 0;
printf("%d", bit);
mask >>=1;
}
return(0);
}
Received on Thu Jul 24 09:17:11 1997
This archive was generated by hypermail 2.1.8 : Fri Aug 01 2003 - 00:31:23 EDT