C/C++の宿題を片付けます 104代目at TECH
C/C++の宿題を片付けます 104代目 - 暇つぶし2ch119:デフォルトの名無しさん
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