Skip to content

Instantly share code, notes, and snippets.

@alexalemi
Created December 3, 2012 19:49
Show Gist options
  • Save alexalemi/4197475 to your computer and use it in GitHub Desktop.
Save alexalemi/4197475 to your computer and use it in GitHub Desktop.
BinaryPlot, showing an array of binary digits for a list of numbers
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