본문 바로가기
Algorithms/simulation

Parity bit

by OKOK 2021. 4. 13.

- char data = 'a';

8비트 중에 7비트는 데이터이고 첫 비트는 parity bit 임. 

이렇게 설계되도록 해서 8비트가 만들어진 것이구나. 핵 신기하네.

- 짝수개가 변형되면 검사를 할 수가 없음

 

#include <stdio.h>
unsigned int hweight(unsigned int w)
{
	unsigned int res = w - ((w >> 1) & 0x55);
	res = (res & 0x33) + ((res >> 2) & 0x33);
	return (res + (res >> 4)) & 0x0F;
}

int main()
{
	char data = 'a';

	if (hweight(data) % 2)
		data |= 0x80;

	//data |= 0x2;
	//data |= 0x4;
	//---------------------------------

	if (hweight(data) % 2 == 0)
		printf("올바른 데이터 입니다.\n");
	else
		printf("변형된 데이터 입니다.\n");
	return 0;
}

'Algorithms > simulation' 카테고리의 다른 글

알고리즘 문제 해결 전략 공부 시작!!  (0) 2021.05.02
Check Sum  (0) 2021.04.24
Bit Reverse  (0) 2021.04.13
Hamming Weight 4  (0) 2021.04.13
Hamming Weight 3  (0) 2021.04.13

댓글