Answer the question
In order to leave comments, you need to log in
How to find the values of individual components?
#include <bits/stdc++.h>
using namespace std;
int main()
{
system("chcp 1251");
char s; /* код системной области */
char d; /* признак «грязного» буфера */
char f; /* признак свободного буфера */
unsigned char b; /* номер блока */
unsigned int UnitStateWord; /* Блок управления */
/* ввод блока управления */
cout << "Введите блок управления \n";
cout << "(16-ричное число от 0 до 0xFFFF) >";
scanf("%x",&UnitStateWord);
/* Выделение составных частей */
s = (UnitStateWord>>13)&0x1F;
d = (UnitStateWord>>11)&1;
f = (UnitStateWord>>9)&1;
b = UnitStateWord&0xFF;
/* вывод результатов */
cout << endl;
cout << "Код системной области" << s << endl;;
cout << "Признак «грязного» буфера " << d << endl;;
cout << "Признак свободного буфера " << f << endl;;
cout << "Номер блока " << b << endl;;
return 0;
}
Answer the question
In order to leave comments, you need to log in
What error is your code giving?
For convenience, try first applying the mask, and then shifting (if the program displays incorrect values):
s = (UnitStateWord & 0xD000) >> 13;
d = (UnitStateWord & 0x0800) >> 11;
f = (UnitStateWord & 0x0200) >> 9;
b = UnitStateWord & 0x00FF;
Your mask for S is not correct (0x1F - 5 bits), judging by the assignment, it should be 7 (3 bits). But in general, this should not affect the result, because. S is the last field and when shifted, free bits will be filled with zeros.
Give an example of an input value and what you get as an output.
It would also not be bad to check the entered UnitStateWord value for falling into the range after entering. Because a variable can take on a much wider range of values.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question