项目作者: chrisrink10

项目描述 :
Visual calculator for bitwise expressions
高级语言: Python
项目地址: git://github.com/chrisrink10/bitcalc.git
创建时间: 2016-01-24T23:17:09Z
项目社区:https://github.com/chrisrink10/bitcalc

开源协议:MIT License

下载


bitcalc

Bitwise operations in C and other derivative languages can be a bit
challenging to visualize and understand if you don’t use them very often.

Now, you can use this simple expression calculator to see a visual
representation of the bitwise operations to verify your intuition or to
learn.

Bitcalc supports all standard C bitwise operators (<<, >>, &, |,
^, and ~) and the basic C arithmetic operators (+, -, *, /, and
%). All of the supported operators follow standard C precedence and
associativity rules. Operator precedence can be changed using parentheses,
as is typically permitted in C.

Getting Started

Bitcalc can be installed easily using pip:

  1. pip install https://github.com/chrisrink10/bitcalc

You can start bitcalc from your console using the bitcalc command.

Examples

Simple operations show the bitwise operation in the format typically used
by students learning basic arithmetic operations to help clarify what is
happening at a bit level.

  1. >>> (1 | 10)
  2. (1 | 10)
  3. 00000001
  4. | 00001010
  5. ------------
  6. 00001011
  7. 11

More complex expressions are solved one-by-one in order of precedence for
each sub-expression to help make clear how each operand in the final
expression was calculated.

  1. >>> (81 & (1 << 3))
  2. (1 << 3)
  3. 00000001
  4. << 3
  5. ------------
  6. 00001000
  7. (81 & (1 << 3))
  8. 01010001
  9. & 00001000
  10. ------------
  11. 00000000
  12. 0

Bitcalc supports arbitrary complex expressions.

  1. >>> (81 & (1 << 3)) | (45 ^ (3 << 2))
  2. (1 << 3)
  3. 00000001
  4. << 3
  5. ------------
  6. 00001000
  7. (81 & (1 << 3))
  8. 01010001
  9. & 00001000
  10. ------------
  11. 00000000
  12. (3 << 2)
  13. 00000011
  14. << 2
  15. ------------
  16. 00001100
  17. (45 ^ (3 << 2))
  18. 00101101
  19. ^ 00001100
  20. ------------
  21. 00100001
  22. ((81 & (1 << 3)) | (45 ^ (3 << 2)))
  23. 00000000
  24. | 00100001
  25. ------------
  26. 00100001
  27. 33

License

MIT License