Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As far as I know it is not possible to see the bits of an integer in Visual Studio, you can see variables in decimal or hexadecimal format in the Locals and Watch windows in the debugger.

Why is this limitation in place and are there any tools/addins to see integers as bits?

share|improve this question

closed as off-topic by Ixrec, Snowman, gnat, GlenH7, amon Mar 14 at 10:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to find or recommend tools, libraries, programming languages, resources (including books, blogs, tutorials, and examples), or projects to undertake are off-topic on Programmers as they attract opinionated answers that won't have lasting value to others. You may be able to get help in The Whiteboard, our chat room." – Ixrec, Snowman, amon
If this question can be reworded to fit the rules in the help center, please edit the question.

Hexadecimal is trivial to translate to binary (1 hex digit = 4 bits), so while you wait for a solution, hexadecimal is almost as good. – delnan Apr 9 '13 at 17:32
For an 32 bit integer, why would you prefer to see 32x "1" and "0"s rather than 4x "0-9A-F"? – user40980 Apr 9 '13 at 17:52
Once you get used to it, it's actually easier to read bit positions in hexadecimal than counting the bits in a long binary number. For example, when you see 0x00050000 you know right away that the 19th and 17th bits (counting from least significant) are set. It's harder to tell that when you see 00000000000001010000000000000000b. Spaces can be inserted to improve readability, but it really doesn't take long for the hex representation to become second nature, and it's much more compact. – Caleb Apr 9 '13 at 18:04
What are you doing that requires you to see which bits are flipped so often? I do embedded hardware design and rarely need to see binary representations. – whatsisname Apr 9 '13 at 20:39
If you have get the hex representation, copy it to the clipboard, then open up calculator, press Alt+3 (or View -> Programmer), click the hex radio button, paste, then you should see the binary representation (depending on your version of Windows, you might need to click the binary radio button to see it) – Erik Mar 11 at 0:35
up vote 4 down vote accepted

I can't speak for the Visual Studio team, but my guess is that it wasn't a limitation that was specifically put in place. Your premise assumes this is the case. It was likely rather a feature that needed to be added and it was determined to be low priority.

It's not clear to me what you're referring to in order to suggest a workaround. Do you mean the Watches window? If so, you can write a function that returns a string of the bits and use that in the Watches window. It's a little awkward, but this would give you the functionality you desire.

EDIT: Ah. You can write a function sort of like such:

namespace util {
    template<typename TInteger>
    std::string to_binary(TInteger value) {
        std::bitset<sizeof(TInteger) * 8> bs(value);
        return bs.to_string();

Standard disclaimer: I don't currently have access to a compiler so this may not compile or work, but it should definitely get you started in the right direction. It may be the case that the templates and the Watches window don't mix well together, but it's fairly trivial to write specific functions for each type.

Usage assuming it's included in the translation unit would be fairly simple: util::to_binary(55) or whatever the case may be in the Watches window.

share|improve this answer
Yes I was referring to the Locals and Watches windows they have either decimal or hex options. – Barış Uşaklı Apr 9 '13 at 17:46

There's no obvious option for it in the UI, but if you put ,b after your watch variable name, it will show the binary representation.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.