sop
sop

Reputation: 3625

How to display the hex value in the Watch panel of VS Code?

I started to use VS Code on Linux and I'd like to see the hex value of a variable near its value. I need it because the variable is a mask, so it is composed of 0's and 1's on certain positions. I did not manage to find a setting or something like it to add it.

Is it possible? I am using C++ code. I see that the addresses are in hex, so is there a way to see the value of a variable in hex, too?

Upvotes: 27

Views: 32600

Answers (4)

For Rust-based debugging, casting it to a *const u8 works. Any spaces need to be double-quoted, which is also probably true for any other GDB-based languages.

"some_var as *const u8"

For anyone confused, the watch lines are passed to the underlying debugger as-is. There's no special handling from VS Code. The other answers are highly language-specific - I assume the hex(somevar) answer is for Python debugging, somevar,h is for Node, (void*)value for C/C++, etc.

Upvotes: 0

Rajeeb barman
Rajeeb barman

Reputation: 29

In the Watch window of VS Code, you can enter the following:

hex(variable name)

Upvotes: 1

Alex E
Alex E

Reputation: 307

Adding ,h etc didn't work for me (at least on lldb on mac).

Try casting the variable to the output type you want:

Example for hex:

(void*)test3x1[1]

Example for integer:

(int)test3x1[1]

Upvotes: 4

Kovalex
Kovalex

Reputation: 2050

In the watch window, type <variable-name>,h.

Upvotes: 54

Related Questions