Created
June 22, 2020 08:49
-
-
Save gitfvb/c4c9bc4102010a7f3066e7b03bdc7bd7 to your computer and use it in GitHub Desktop.
Binary options in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
HINTS | |
# check bitwise: https://ingogegenwarth.wordpress.com/2016/11/17/powershell-and-bit-field-attributes/ | |
#> | |
# Good example because the cleverreach api checks the details to download bitwise... those are the values | |
$cleverreachDetails = @{ | |
events = 1 | |
orders = 2 | |
tags = 4 | |
} | |
# We can output those keys sorted by the value | |
$cleverreachDetails.GetEnumerator() | Sort-Object -Property Value | |
# To summarise which bits are set and which details are contained, we can create an array like this | |
$detailsToLoad = foreach ($bit in ($cleverreachDetails.GetEnumerator() | Sort-Object -Property Value )) { | |
if (($value -band $bit.Value) -ne 0){ | |
$bit.Key | |
} | |
} | |
# And we can output or check something in that array like | |
$detailsToLoad | |
$detailsToLoad.Contains('tags') | |
# And btw... to calculate between decimal and binary... here is another example | |
[convert]::ToInt32("0111",2) # -> 7 | |
[convert]::ToString("7",2) # -> 111 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment