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