Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
4  
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
    
It would have been nice to see the actual bits instead of figuring out which bit is set each time I see a hex value. For example when I see 0x00000020 it takes a while to process that it means the 5th bit is set. –  Barış Uşaklı Apr 9 '13 at 17:52
1  
For an 32 bit integer, why would you prefer to see 32x "1" and "0"s rather than 4x "0-9A-F"? –  MichaelT Apr 9 '13 at 17:52
    
Just for convenience and to remove the need to figure out which bits are set when you look at a hexadecimal number. –  Barış Uşaklı Apr 9 '13 at 17:54
2  
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
show 1 more comment

1 Answer

up vote 3 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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