Home > Back-end >  Bosses know how to write this in c
Bosses know how to write this in c

Time:12-29

In 56 h and 59 h unit has two BCD number, they merge to 59 h unit, requires the original 56 h BCD in high, 59 h in low, try to write programs to complete,

CodePudding user response:

Make sure the size, then there is a pointer, operation,

CodePudding user response:

Fyi:
 # include & lt; stdio.h> 
#include
#include
Unsigned int iv, I;
Unsigned char BCD [5].//fixed-length 10
BCDUnsigned char sv [11].
Void main () {
Iv=123456789;//the biggest 10 are unsigned integers
//INT2BCD
Sprintf (sv, "% 010 u", iv);
for (i=0; i<10; I +=2) {
BCD [I/2]=(sv [I] <4) | (sv [I + 1] & amp; 0 x0f);
}
Printf (" BCD=% 02 x % 02 02 x % 02 x % 02 x x % \ n ", BCD [0], BCD [1], BCD [2], BCD [3], BCD [4]);
//BCD2INT
for (i=0; i<10; I +=2) {
Sv [I]='0' | (BCD [I/2] & gt;> 4);
Sv=[I + 1] '0' | (BCD [I/2] & amp; 0 x0f);
}
Sscanf (sv % 010 "u", & amp; Iv);
Printf (" iv=% 010 u \ n ", iv);
getch();
}
  • Related