Saturday 21 May 2011

Hex / Binary / Decimal / Octal number conversion in WinDbg

Normally if I need to do any conversions between different number formats I’ll just do it in my head (yeah, right!) or load calc.exe.   A while back one of my posts showed how easy it was to convert numbers in PowerShell e.g.

[Convert]::ToString(734, 2)

will convert 734 to binary, and

[Convert]::ToString(179, 16)

will convert 179 to hexadecimal.

It’s just as easy to do it in WinDbg if you need to do any conversions while debugging using .formats.  The benefit of .formats is that it will give you all the available conversions it can, so if you were to enter .formats 0y1100011 you would see:

image

To make sure that WinDbg is aware of the number format you are entering as a parameter you give it the relevant prefix: 0y (binary), 0x(hexadecimal), 0t (octal) & 0n (decimal).  You can also set the default number base using the n command which means all numbers entered will be interpreted as such. Just entering n will show the current number base e.g.

image

And to change it to octal…

image

No comments:

Post a Comment