0

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?

2
  • C++ doesn't have native support for binary literals (assuming that's what you're trying to do). Commented Mar 3, 2014 at 5:34
  • 1
    How you get 204???????? (11111110 mod 256) = 198 Commented Mar 3, 2014 at 5:48

1 Answer 1

4

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.