Created
December 3, 2012 19:49
-
-
Save alexalemi/4197475 to your computer and use it in GitHub Desktop.
BinaryPlot, showing an array of binary digits for a list of numbers
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
BinaryPlot[nums_, K_: 0, opts : OptionsPattern[BinaryPlot]] := | |
MatrixPlot[ | |
Table[BitGet[nums[[j]], i], {j, 1, Length[nums]}, {i, 0, | |
If[K > 0, K, nums // Log2 // Floor // Max]}], | |
Evaluate@FilterRules[{opts, { DataReversed -> {False, True}, | |
Mesh -> True, FrameTicks -> None, Frame -> False }}, | |
Options@MatrixPlot]] | |
BinaryPlot::usage = | |
"BinaryPlot[list] Creates and array showing the binary \ | |
representation of a list of numbers. Takes the same options as \ | |
MatrixPlot | |
BinaryPlot[list, K] shows the first K binary digits, by default \ | |
show all (K=0)"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment