1
+ """
2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
+ FILE: Binarycalculator.py
4
+ DESCRIPTION: A module that provides all necessary stuff to handle binary
5
+ and hex conversions and interpretions for a binary calculator.
6
+ AUTHOR: Jochen Bauer
7
+ CREATION DATE: 20170414
8
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9
+ LICENSE: GPL version 3
10
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11
+ This file is part of MonkeyByte.
12
+
13
+ MonkeyByte is free software: you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation, either version 3 of the License, or
16
+ (at your option) any later version.
17
+
18
+ MonkeyByte is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with MonkeyByte. If not, see <http://www.gnu.org/licenses/>.
25
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26
+ """
27
+
28
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29
+ # ~~~~~~~~~~~~~~~~~~~~~ IMPORTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
+
32
+ import bitstring
33
+
34
+ class BinCalc :
35
+ """ the main calculator class """
36
+ def __init__ (self , currentValue = 0 ):
37
+ self ._currentValue = currentValue
38
+ self ._currentBitarray = bitstring .BitArray (Bits ().int = _currentValue )
39
+
40
+ def hex (self ):
41
+ """ Returns a hexadecimal string representation of the current value """
42
+ return str (hex (self ._currentValue ))[2 :]
43
+
44
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
+ # ~~~~~~~~~~~~~~~~~~~~~ PROPERTIES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
+
48
+ @property
49
+ def currentValue (self ):
50
+ """ currentValue getter """
51
+ return self ._currentValue
52
+
53
+ @currentValue .setter
54
+ def currentValue (self , value ):
55
+ """ currentValue setter """
56
+ self ._currentValue = value
57
+ self .
58
+
0 commit comments