C/C++の宿題を片付けます 104代目 at TECH
[2ch|▼Menu]
119:デフォルトの名無しさん
08/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;
}
できたから載せただけ。


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

4969日前に更新/299 KB
担当:undef