BCD *ascii_to_BCD(BCD *bcd_value, char *ascii_value, int ascii_length) { int i; int j; int temp_bcd; int temp_ascii_digit; j = 0; for (i = 0; i < ascii_length/2; i ++) { temp_ascii_digit = ascii_value[j++]; if (temp_ascii_digit < '0' || temp_ascii_digit > '9') { printf("Invalid ascii to BCD conversion: input char = %c\n", temp_ascii_digit); exit(1); } temp_bcd = (temp_ascii_digit & 15) << 4; temp_ascii_digit = ascii_value[j++]; if (temp_ascii_digit < '0' || temp_ascii_digit > '9') { printf("Invalid ascii to BCD conversion: input char = %c\n", temp_ascii_digit); exit(1); } temp_bcd += temp_ascii_digit & 15; bcd_value[i] = temp_bcd; } return(bcd_value); }