- 119 名前:デフォルトの名無しさん mailto:sage [2008/02/09(土) 16:24:15 ]
- >>118の続き
int str2bit(char *str, char *pal, int cur, int max) { int res = 0; int i = 0; int cnt =0; char t_byte[16+1]; memset(t_byte, 0, sizeof(t_byte)); for ( i = 0; i < 15; i++ ) { t_byte[i] = ( cur + i >= max ) ? '0' : str[cur + i]; if ( t_byte[i] == '1' ) { cnt++; res += 1; } res <<= 1; } if ( *pal == '0' ) { /* 偶数パリティ */ if ( cnt % 2 ) res++; } else { /* 奇数パリティ */ if ( !(cnt % 2 ) ) res++; } return res; } できたから載せただけ。
|

|