bool Int2BCD( unsigned int num, char* bcd ) { if( num > 255 ) // out of range return false; int len = 0; char buff[8] = {0}; while ( num != 0 ) { if( num % 2 == 1 ) buff[len++] = '1'; else buff[len++] = '0'; num = num / 2; } for( int i=0; i < 8; i++ ) { if( i < len ) bcd[7-i] = buff[i]; else bcd[7-i] = '0'; } }
谢谢。有一段代码 void DecBcd(unsigned char* *s,int n,int m) {
int j; if( m < 0 ) { bSign = FALSE; m = -m; } for( j=0 ; j<n ; j++ ) { **s = (unsigned char)(m%100); **s += **s/10*6; (*s)++; m /= 100; } } m是要转换的值,n是转换的字节数。 楼上能给我解释一下码?
谢谢。有一段代码 void DecBcd(unsigned char* *s,int n,int m) {
int j; if( m < 0 ) { m = -m; } for( j=0 ; j<n ; j++ ) { **s = (unsigned char)(m%100); **s += **s/10*6; (*s)++; m /= 100; } } m是要转换的值,n是转换的字节数。 楼上能给我解释一下码?
bool Int2BCD( unsigned int num, char* bcd )
{
if( num > 255 ) // out of range
return false; int len = 0;
char buff[8] = {0}; while ( num != 0 ) {
if( num % 2 == 1 )
buff[len++] = '1';
else
buff[len++] = '0'; num = num / 2;
} for( int i=0; i < 8; i++ )
{
if( i < len )
bcd[7-i] = buff[i];
else
bcd[7-i] = '0';
}
}
void DecBcd(unsigned char* *s,int n,int m)
{
int j; if( m < 0 )
{
bSign = FALSE;
m = -m;
} for( j=0 ; j<n ; j++ )
{
**s = (unsigned char)(m%100);
**s += **s/10*6;
(*s)++;
m /= 100;
}
}
m是要转换的值,n是转换的字节数。
楼上能给我解释一下码?
void DecBcd(unsigned char* *s,int n,int m)
{
int j; if( m < 0 )
{
m = -m;
} for( j=0 ; j<n ; j++ )
{
**s = (unsigned char)(m%100);
**s += **s/10*6;
(*s)++;
m /= 100;
}
}
m是要转换的值,n是转换的字节数。
楼上能给我解释一下码?