Set right-adjacent bits: Difference between revisions
Content added Content deleted
Line 374: | Line 374: | ||
<lang Mathematica>ClearAll[ShowSetRightBits] |
<lang Mathematica>ClearAll[ShowSetRightBits] |
||
ShowSetRightBits[b_String,n_Integer]:=Module[{poss,chars}, |
ShowSetRightBits[b_String,n_Integer]:=Module[{poss,chars}, |
||
chars=Characters[b]; |
chars=Characters[b]; |
||
poss=Position[chars,"1"]; |
poss=Position[chars,"1"]; |
||
poss=Union[Flatten[Outer[Plus,poss,Range[n]]]]; |
poss=Union[Flatten[Outer[Plus,poss,Range[n]]]]; |
||
{{"In :",b},{"Out:",StringJoin[ReplacePart[chars,(List/@poss)->"1"]]}}//Grid |
{{"In :",b},{"Out:",StringJoin[ReplacePart[chars,(List/@poss)->"1"]]}}//Grid |
||
] |
] |
||
ShowSetRightBits["1000",2] |
ShowSetRightBits["1000",2] |