다음은 문자의 비트 표현을위한 프로그램입니다. 그러나 나는 그것이 옳고 그른 표현을 보여주고 있는지 모른다. 의심스러운 단위 (붉은 색)가 있습니다. 문자의 비트 표현 C++
당신은 (그것이 바로 인 경우)이 나 무엇을이 장치가 안하면 내 코드를 잘못 걸 설명 할 수 있습니다. 감사합니다#include "stdafx.h"
#include "iostream"
using namespace std;
struct byte {
unsigned int a:1;
unsigned int b:1;
unsigned int c:1;
unsigned int d:1;
unsigned int e:1;
unsigned int f:1;
unsigned int g:1;
unsigned int h:1;
};
union SYMBOL {
char letter;
struct byte bitfields;
};
int main() {
union SYMBOL ch;
cout << "Enter your char: ";
while(true) {
ch.letter = getchar();
if(ch.letter == '\n') break;
cout << "You typed: " << ch.letter << endl;
cout << "Bite form = ";
cout << ch.bitfields.h;
cout << ch.bitfields.g;
cout << ch.bitfields.f;
cout << ch.bitfields.e;
cout << ch.bitfields.d;
cout << ch.bitfields.c;
cout << ch.bitfields.b;
cout << ch.bitfields.a;
cout << endl << endl;
}
}
이 코드는 코드가 정확하므로 자원 요청 (여기서는 ASCII 문자 값 표)으로 축소되어 나타납니다. – Useless
@Useless : 포스터 _believes_은 버그이므로 다시 가져올 수 있습니다 주제에. –
그건 그렇고, 컴퓨터 용어는 일반적으로 "바이트"대신에 "바이트"라고 쓰여져 있습니다 –