3

I'm using the Windows 10 Calculator in Programmer mode to convert hex to decimal. The issue is the calculator defaults to signed.

Set to: DWORD

HEX: A08A 5A52

Result:

DEC: ‭-1601545646‬

How do I set it to give an unsigned value? I find I can get unsigned if I just use a larger memory value, setting it to QWORD, but then I run into problems if using a unsigned 32-bit value.

phuclv
  • 30,396
  • 15
  • 136
  • 260
John Snow
  • 153

2 Answers2

1

How do I set it to give an unsigned value?

Binary files are represented as signed 2’s compliment within the Windows Calculator. As such, Windows Calculator, doesn’t support unsigned binary values.

I suggest using a different calculator program for your needs.

Ramhound
  • 44,080
1

Use PowerShell instead. Just type 0xA08A5A52L and the result in decimal will be printed out. If you have PowerShell 6.2 or newer you can also use 0xA08A5A52UL. The L and UL suffixes denote long and ulong types in .NET respectively

PowerShell demo

Windows Calculator doesn't have the ability to deal with unsigned values as of now, so you have to use a wider type which is QWORD for DWORD values. You'll only run into problems when dealing with unsigned 64-bit values. For 0xA08A5A52 if you're operating in DWORD mode then you'll need to change to QWORD mode then do a bitwise AND with 0xFFFFFFFF to clear the high order bits to get the unsigned value 2693421650 correctly


Off-topic, but in fact if you want a calculator for programmers then PowerShell would be more appropriate because it's far more versatile and powerful than Calculator. I'll show some more examples on how PowerShell can be used for that purpose. For doing math in .NET (and inherently PowerShell) there exists math functions from low to high levels, mainly from the .NET Math class and Numerics namespace. You'll put class .NET types inside [], like [math] or [system.math] for the Math class (PowerShell is case-insensitive). Apart from that there are some other things that may be useful to programmers:

  • Bitwise operations (bitwise operators begin with -b except shift operators)

    [uint64]::MaxValue/3 + (-bnot 20) + (1L -shl 22) + (0x23 -band 0x34)
    
  • Big integer math: [bigint]::Pow([uint64]::MaxValue, 20)

  • Arbitrary integer and floating-point math expressions

    1.56 + 0.23/[math]::Pow([math]::Sqrt([math]::Log(20) + [math]::Sin([math]::PI/3)), 4)
    
  • Math on decimal type (128-bit): 1.23d * 3.45d / 28

  • Math on 128-bit integer types

  • Matrix, quaternion, plane, vector, complex... math

  • Calculate file or object sizes: Use number suffixes 12.5GB + 5.8MB + 1392KB for binary units and 12.5e9 + 5.8e6 + 1392e3 for decimal units (G = 1e9, M = 1e6, K = 1e3)

  • Convert to/from base64: [Convert]::ToBase64String and [Convert]::FromBase64String

  • Date/time manipulation. For example convert from raw Epoch values to datetime and vice versa

      [datetime]::FromFileTime(0x01d15614cbaee92c)
      [datetime]::ParseExact("08-12-2012","dd-MM-yyyy", `
              [Globalization.CultureInfo]::InvariantCulture) 
    
  • String formatting and base conversion. Anything that String.Format in .NET supports will work. For more information read about the formatting operator. You can also do advanced string and regex manipulation. Some examples:

      'somestring'.Substring(4) * 3 -replace 'ings', 'eet'
      '{0:X}' -f (0x12 + 34)
      [convert]::ToString(0x12 + 34, 16)
      'This is an emoji' + [char]::ConvertFromUtf32(0x1F60A)
    
  • Direct XML, CSV, JSON... manipulation

  • Call functions in *.SO/*.DLL files directly

  • GUI programming. Here's a small sample clipboard history app

    PowerShell sample

For more information read

or follow Dr Scripto's blog

phuclv
  • 30,396
  • 15
  • 136
  • 260