DevToys icon indicating copy to clipboard operation
DevToys copied to clipboard

Bitmask calculator

Open panuoksala opened this issue 2 years ago • 6 comments

What's the Problem?

Let's say I have a number 38768594 which is a number containing multiple bit masks. 2^0 2^1 2^2 2^3 etc.

I would like to see which flags are enabled. For example 2^2=4 => bitmask 4 is enabled for this number.

Solution/Idea

Present bitmask in array format and in numeric format. So that it is easy to check which bits are true for the number.

Alternatives

Priorities

Capability Priority
Show bitmask in number Must
Show bitmask in array format Should

DevToys Version

Version 1.0.2.0 | X64 | RELEASE | b972462 | b972462

Comments

No response

panuoksala avatar Feb 16 '22 14:02 panuoksala

Does the binary number converter satisfy your requirements?

image

The binary number format field is essentially an array showing the bit status from left to right, in groups of 4 for easy counting.

Do you need something different to or more than this? 😊

jwfxpr avatar Feb 17 '22 04:02 jwfxpr

That is actually very close. My main problem is that I have an enum in my code: NotSet = 0, InSale = 1, Sold = 2, Cancelled = 4, PendingCancel = 8, PendingSale = 16, PendingReturn = 32, Returned = 64, ... SomethingElse = 70368744177664,

Now I have an integer in database that says that the status is X. I would like to see which of the flags are enabled for it. I think I can use the binary number to keep track of flags, but there are quite many of them. I know it is hard to map between enum values and the binaries in DevToys, but just wanted to raise this issue into radar.

panuoksala avatar Feb 17 '22 06:02 panuoksala

On that binary number it would be maybe cool to indicate, that which of the exponential values the bits are. Like 0100 ^1 or something like that.

panuoksala avatar Feb 17 '22 06:02 panuoksala

Ah, I see.

Perhaps this could be combined with a more complete bitwise calculator tool, something similar to https://miniwebtool.com/bitwise-calculator/, with the addition that all the fields (input and output) can also show the bits that are true in expontial format, like you suggested? Something like:

  • A number base selector for the input numbers
  • 2 fields for input numbers, with a bitmask sum displayed for each: I.e., an input [ 38768594 ] => 2^1 + 2^4 + 2^6 + 2^7 + ...
  • 3 output fields, one each for AND, OR, and XOR of the two inputs, each of which also shows the bitmask sum that it breaks down to

That seems like a versatile and useful tool to me, I'd use that. How to best display the exponents of the bits is the tricky part, I think.

jwfxpr avatar Feb 17 '22 08:02 jwfxpr

Yeah exactly something like the miniwebtool. The problem with miniwebtool is that you need to input numbers one by one to see if they are active, it does not give good list of values that are active.

Yes the display logic might be trickiest part. This page has nice idea about visualization, but the UX is the problem: https://visualgo.net/en/bitmask

panuoksala avatar Feb 17 '22 08:02 panuoksala

this should have the capability of displaying floats too.

expikr avatar Feb 24 '22 11:02 expikr