Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created June 22, 2020 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitfvb/c4c9bc4102010a7f3066e7b03bdc7bd7 to your computer and use it in GitHub Desktop.
Save gitfvb/c4c9bc4102010a7f3066e7b03bdc7bd7 to your computer and use it in GitHub Desktop.
Binary options in powershell
<#
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