Last active
September 15, 2026 18:49
-
-
Save ninmonkey/079412952e86f26876f2d72b5a7975ea to your computer and use it in GitHub Desktop.
Convert Offset to Processor Affinity Bitflags.ps1
This file contains hidden or 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
| <# | |
| Output: | |
| ProcessNum BitFlag BitStr | |
| ---------- ------- ------ | |
| 10 1024 000000000000010000000000 | |
| 11 2048 000000000000100000000000 | |
| 12 4096 000000000001000000000000 | |
| 13 8192 000000000010000000000000 | |
| 14 16384 000000000100000000000000 | |
| 15 32768 000000001000000000000000 | |
| 16 65536 000000010000000000000000 | |
| 17 131072 000000100000000000000000 | |
| 18 262144 000001000000000000000000 | |
| 19 524288 000010000000000000000000 | |
| Merged BitStr HexStr | |
| ------ ------ ------ | |
| 1047552 11111111110000000000 ffc00 | |
| #> | |
| filter ToBits { | |
| # visualize number as bitstring | |
| param( [int] $Width = 4 ) | |
| [Convert]::ToString($_, 2).PadLeft($Width, '0') | |
| } | |
| filter ToHex { | |
| # visualize number as hex string | |
| $Input | % ToString 'x' | |
| } | |
| function FlagForProcessor { | |
| # Converts processor number 0, 1, 2 to bitflag 0b1, 0b10, 0b100, etc... | |
| param( [int] $ProcessNum = 0 ) | |
| [int] $Bits = 1 -shl $ProcessNum | |
| [pscustomobject]@{ | |
| ProcessNum = $ProcessNum | |
| BitFlag = $Bits | |
| BitStr = $Bits | ToBits -Width 24 | |
| } | |
| } | |
| function MergeFlags { | |
| # use a BitWise-Or operator to accumulate multiple flags | |
| param( $flags ) | |
| $accum = 0 | |
| foreach( $cur in $flags ) { | |
| $accum = $accum -bor $cur | |
| } | |
| $accum | |
| } | |
| # get flags for offset 10 to 19, warning, starts at 0 | |
| $flags = 10..19 | %{ | |
| FlagForProcessor $_ | |
| } | |
| $merged = MergeFlags $flags.BitFlag | |
| # display final summary in a couple of number formats | |
| $flags | ft -auto | |
| [pscustomobject]@{ | |
| Merged = $merged | |
| BitStr = $merged | ToBits | |
| HexStr = $Merged | ToHex | |
| } | ft -auto |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment