문제

I have a variable type Byte and pass the value like here

BYTE a;
a=11111110;

but when I debugged the code I saw in visual c++ that the value of a is 204. but it must be 244. why the value is not true?

올바른 솔루션이 없습니다

다른 팁

11111110 is a decimal number, not a binary one.

If you want to set it to the binary value 11111110, use 0xfe instead.

In any case, I'm not entirely sure you have the value correct, based on the fact that you also state it should be 244 when it is, in fact 254.

That's because 11111110 % 256 is 198 rather than 204 and the most likely case is that it will simply wrap. In fact, in VC++ 2010, 198 is the result I get from similar code:

#include <iostream>
#include <windows.h>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {
    BYTE a;
    a = 11111110;
    std::cout << (int)a << '\n';
    return 0;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top