baseconvert 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2023 BreadMakesYouFull
3
+ Copyright (c) 2016 squdle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # Include the license file
2
+ include LICENSE.txt
3
+ include VERSION.txt
4
+ include README.md
5
+ include README.rst
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.1
2
+ Name: baseconvert
3
+ Version: 2.0.0
4
+ Summary: Convert numbers between bases.
5
+ Home-page: https://github.com/BreadMakesYouFull/baseconvert.git
6
+ Author: squdle, BreadMakesYouFull
7
+ License: MIT
8
+ Keywords: base bases radix numeral system number hex dec bin hexidecimalbinary decimal fraction fractions integer convert gui
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Topic :: Education
13
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ License-File: LICENSE.txt
17
+ Requires-Dist: pyside6
18
+
19
+ baseconvert
20
+ ===========
21
+
22
+ Convert any rational number, from any (positive integer) base, to any
23
+ (positive integer) base. Output numbers as tuple or string.
24
+
25
+ - Any rational number
26
+ - Arbitrary precision
27
+ - Fractions
28
+ - Recurring/repeating fractional digits.
29
+ - Input numbers as tuple or string or number.
30
+ - Output numbers as tuple or string.
31
+
32
+ MIT License (MIT) Copyright (c) 2016 BreadMakesYouFull
33
+ MIT License (MIT) Copyright (c) 2016 squdle
34
+
35
+ `github <https://github.com/BreadMakesYouFull/baseconvert>`__
36
+
37
+ Requires
38
+ --------
39
+
40
+ - Python 3
41
+
42
+ Install / Uninstall
43
+ -------------------
44
+
45
+ Install:
46
+
47
+ ::
48
+
49
+ pip install baseconvert
50
+
51
+ Uninstall:
52
+
53
+ ::
54
+
55
+ pip uninstall baseconvert
56
+
57
+ Quickstart
58
+ ----------
59
+
60
+ ::
61
+
62
+ # base(number, input_base, output_base)
63
+
64
+ >>> base((15, 15, 0, ".", 8), 16, 10)
65
+ (4, 0, 8, 0, '.', 5)
66
+
67
+ >>> base("FF0.8", 16, 10, string=True)
68
+ '4080.5'
69
+
70
+ >>> base("4080.5", 10, 16, string=True)
71
+ 'FF0.8'
72
+
73
+ Or from command line
74
+
75
+ ::
76
+
77
+ $ echo 4080.5 | python -m baseconvert -i 10 -o 16
78
+ FF0.8
79
+
80
+ $ python -m baseconvert -n 4080.5 -i 10 -o 16
81
+ FF0.8
82
+
83
+ Tuple representation
84
+ --------------------
85
+
86
+ Numbers are represented as a sequence of digits. Each digit is a base-10
87
+ integer value. The radix point, which separates the integer and
88
+ fractional parts, is denoted by a string period.
89
+
90
+ ::
91
+
92
+ (int, int, int, ... , '.', ... , int, int, int)
93
+ ( integer part , '.', fractional part )
94
+
95
+ String representation
96
+ ---------------------
97
+
98
+ String digits (after z the values are in ascending Unicode):
99
+
100
+ ::
101
+
102
+ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
103
+
104
+ | Value | Representation |
105
+ |---------|----------------|
106
+ | 0 - 9 | 0 - 9 |
107
+ | 10 - 53 | A - Z |
108
+ | 36 - 61 | a - z |
109
+ | 62 + | unicode 123 + |
110
+
111
+ For bases higher than 61 it's recommended to use tuple representation.
112
+
113
+ Examples
114
+ --------
115
+
116
+ ::
117
+
118
+ # base(number, input_base, output_base)
119
+ >>> n = (15,15,".",0,8)
120
+ >>> base(n, 16, 10)
121
+ (2, 5, 5, '.', 0, 3, 1, 2, 5)
122
+ >>> base(n, 16, 10, string=True)
123
+ '255.03125'
124
+
125
+ >>> base("FF.08", 16, 10) == base((15,15,".",0,8), 16, 10)
126
+ True
127
+
128
+ # A callable BaseConverter object can also be created.
129
+ # This is useful for when several numbers need to be converted.
130
+
131
+ >>> b = BaseConverter(input_base=16, output_base=8)
132
+ >>> b("FF")
133
+ (3, 7, 7)
134
+ >>> b((15, 15))
135
+ (3, 7, 7)
136
+ >>> b("FF") == b((15,15))
137
+ True
138
+
139
+ >>> base(0.1, 3, 10, string=True)
140
+ '0.[3]'
141
+
142
+ Recurring digits
143
+ ~~~~~~~~~~~~~~~~
144
+
145
+ Recurring digits at the end of a fractional part will be enclosed by "["
146
+ and "]" in both string and tuple representation. This behavior can be
147
+ turned off by setting the recurring argument of base or BaseConverter
148
+ object to False.
149
+
150
+ ::
151
+
152
+ >>> base("0.1", 3, 10, string=True)
153
+ '0.[3]'
154
+ >>> base("0.1", 3, 10, string=True, recurring=False)
155
+ '0.3333333333'
156
+
157
+ Max fractional depth
158
+ ~~~~~~~~~~~~~~~~~~~~
159
+
160
+ Integer parts are always of arbitrary size. Fractional depth (number of
161
+ digits) can must be specified by setting the max\_depth argument of base
162
+ or a BaseConverter object (default 10).
163
+
164
+ ::
165
+
166
+ >>> base("0.2", 10, 8)
167
+ (0, '.', 1, 4, 6, 3, 1, 4, 6, 3, 1, 4)
168
+ >>> base("0.2", 10, 8, max_depth=1)
169
+ (0, '.', 1)
@@ -0,0 +1,145 @@
1
+ baseconvert
2
+ ===========
3
+
4
+ Convert rational numbers between bases.
5
+
6
+ ![](./preview.gif)
7
+
8
+ [https://github.com/BreadMakesYouFull/baseconvert](https://github.com/BreadMakesYouFull/baseconvert)
9
+
10
+ ## Install
11
+
12
+ Requires:
13
+ * python 3
14
+ * pyside6 for GUI
15
+
16
+ ```
17
+ # Install from pypi via pip
18
+ pip install baseconvert
19
+
20
+ # ...or install from source
21
+ git clone https://github.com/BreadMakesYouFull/baseconvert
22
+ python -m venv venv
23
+ # (pyside6 can be removed from setup.py if needed)
24
+ ./venv/bin/pip install .
25
+
26
+ ```
27
+
28
+ ## Run UI
29
+
30
+ ```
31
+ baseconvert
32
+ ```
33
+
34
+ ## Python Library
35
+
36
+ Convert any rational number, from any positive integer base, to any positive integer base.
37
+
38
+ Output numbers as tuple or string.
39
+
40
+ - Any rational number
41
+ - Arbitrary precision
42
+ - Fractions
43
+ - Recurring/repeating fractional digits.
44
+ - Input numbers as tuple or string or number.
45
+ - Output numbers as tuple or string.
46
+
47
+ ```
48
+ # base(number, input_base, output_base)
49
+ >>> base((15, 15, 0, ".", 8), 16, 10)
50
+ (4, 0, 8, 0, '.', 5)
51
+
52
+ >>> base("FF0.8", 16, 10, string=True)
53
+ '4080.5'
54
+
55
+ >>> base("4080.5", 10, 16, string=True)
56
+ 'FF0.8'
57
+ ```
58
+
59
+ Or from command line
60
+
61
+ $ echo 4080.5 | python -m baseconvert -i 10 -o 16
62
+ FF0.8
63
+
64
+ $ python -m baseconvert -n 4080.5 -i 10 -o 16
65
+ FF0.8
66
+
67
+ ### Tuple representation
68
+
69
+ Numbers are represented as a sequence of digits.
70
+ Each digit is a base-10 integer value.
71
+ The radix point, which separates the integer and fractional parts,
72
+ is denoted by a string period.
73
+
74
+ (int, int, int, ... , '.', ... , int, int, int)
75
+ ( integer part , '.', fractional part )
76
+
77
+ ### String representation
78
+
79
+ String digits (after z the values are in ascending Unicode):
80
+
81
+ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
82
+
83
+ | Value | Representation |
84
+ |---------|----------------|
85
+ | 0 - 9 | 0 - 9 |
86
+ | 10 - 35 | A - Z |
87
+ | 36 - 61 | a - z |
88
+ | 62 + | unicode 123 + |
89
+
90
+ For higher bases it's recommended to use tuple representation.
91
+
92
+ ### Examples
93
+
94
+ # base(number, input_base, output_base)
95
+ >>> n = (15,15,".",0,8)
96
+ >>> base(n, 16, 10)
97
+ (2, 5, 5, '.', 0, 3, 1, 2, 5)
98
+ >>> base(n, 16, 10, string=True)
99
+ '255.03125'
100
+
101
+ >>> base("FF.08", 16, 10) == base((15,15,".",0,8), 16, 10)
102
+ True
103
+
104
+ # A callable BaseConverter object can also be created.
105
+ # This is useful for when several numbers need to be converted.
106
+
107
+ >>> b = BaseConverter(input_base=16, output_base=8)
108
+ >>> b("FF")
109
+ (3, 7, 7)
110
+ >>> b((15, 15))
111
+ (3, 7, 7)
112
+ >>> b("FF") == b((15,15))
113
+ True
114
+
115
+ >>> base(0.1, 3, 10, string=True)
116
+ '0.[3]'
117
+
118
+ ### Recurring digits
119
+
120
+ Recurring digits at the end of a fractional part will be enclosed by
121
+ "[" and "]" in both string and tuple representation.
122
+ This behavior can be turned off by setting the recurring argument of base or
123
+ BaseConverter object to False.
124
+
125
+ >>> base("0.1", 3, 10, string=True)
126
+ '0.[3]'
127
+ >>> base("0.1", 3, 10, string=True, recurring=False)
128
+ '0.3333333333'
129
+
130
+ ### Max fractional depth
131
+
132
+ Integer parts are always of arbitrary size.
133
+ Fractional depth (number of digits) can must be specified by setting the
134
+ max_depth argument of base or a BaseConverter object (default 10).
135
+
136
+ >>> base("0.2", 10, 8)
137
+ (0, '.', 1, 4, 6, 3, 1, 4, 6, 3, 1, 4)
138
+ >>> base("0.2", 10, 8, max_depth=1)
139
+ (0, '.', 1)
140
+
141
+ ### Exact...ish
142
+
143
+ You can also set ``max_depth=0`` or use the flag ``exact=True``, which are equivalent. These "Exact" results will be only precise only up to the value of ``baseconvert.baseconvert.MAX_DEPTH`` which you may also override, but is limited by default for speed.
144
+
145
+ This is only relevant for fractional numbers, integer values should always be accurate.
@@ -0,0 +1,151 @@
1
+ baseconvert
2
+ ===========
3
+
4
+ Convert any rational number, from any (positive integer) base, to any
5
+ (positive integer) base. Output numbers as tuple or string.
6
+
7
+ - Any rational number
8
+ - Arbitrary precision
9
+ - Fractions
10
+ - Recurring/repeating fractional digits.
11
+ - Input numbers as tuple or string or number.
12
+ - Output numbers as tuple or string.
13
+
14
+ MIT License (MIT) Copyright (c) 2016 BreadMakesYouFull
15
+ MIT License (MIT) Copyright (c) 2016 squdle
16
+
17
+ `github <https://github.com/BreadMakesYouFull/baseconvert>`__
18
+
19
+ Requires
20
+ --------
21
+
22
+ - Python 3
23
+
24
+ Install / Uninstall
25
+ -------------------
26
+
27
+ Install:
28
+
29
+ ::
30
+
31
+ pip install baseconvert
32
+
33
+ Uninstall:
34
+
35
+ ::
36
+
37
+ pip uninstall baseconvert
38
+
39
+ Quickstart
40
+ ----------
41
+
42
+ ::
43
+
44
+ # base(number, input_base, output_base)
45
+
46
+ >>> base((15, 15, 0, ".", 8), 16, 10)
47
+ (4, 0, 8, 0, '.', 5)
48
+
49
+ >>> base("FF0.8", 16, 10, string=True)
50
+ '4080.5'
51
+
52
+ >>> base("4080.5", 10, 16, string=True)
53
+ 'FF0.8'
54
+
55
+ Or from command line
56
+
57
+ ::
58
+
59
+ $ echo 4080.5 | python -m baseconvert -i 10 -o 16
60
+ FF0.8
61
+
62
+ $ python -m baseconvert -n 4080.5 -i 10 -o 16
63
+ FF0.8
64
+
65
+ Tuple representation
66
+ --------------------
67
+
68
+ Numbers are represented as a sequence of digits. Each digit is a base-10
69
+ integer value. The radix point, which separates the integer and
70
+ fractional parts, is denoted by a string period.
71
+
72
+ ::
73
+
74
+ (int, int, int, ... , '.', ... , int, int, int)
75
+ ( integer part , '.', fractional part )
76
+
77
+ String representation
78
+ ---------------------
79
+
80
+ String digits (after z the values are in ascending Unicode):
81
+
82
+ ::
83
+
84
+ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
85
+
86
+ | Value | Representation |
87
+ |---------|----------------|
88
+ | 0 - 9 | 0 - 9 |
89
+ | 10 - 53 | A - Z |
90
+ | 36 - 61 | a - z |
91
+ | 62 + | unicode 123 + |
92
+
93
+ For bases higher than 61 it's recommended to use tuple representation.
94
+
95
+ Examples
96
+ --------
97
+
98
+ ::
99
+
100
+ # base(number, input_base, output_base)
101
+ >>> n = (15,15,".",0,8)
102
+ >>> base(n, 16, 10)
103
+ (2, 5, 5, '.', 0, 3, 1, 2, 5)
104
+ >>> base(n, 16, 10, string=True)
105
+ '255.03125'
106
+
107
+ >>> base("FF.08", 16, 10) == base((15,15,".",0,8), 16, 10)
108
+ True
109
+
110
+ # A callable BaseConverter object can also be created.
111
+ # This is useful for when several numbers need to be converted.
112
+
113
+ >>> b = BaseConverter(input_base=16, output_base=8)
114
+ >>> b("FF")
115
+ (3, 7, 7)
116
+ >>> b((15, 15))
117
+ (3, 7, 7)
118
+ >>> b("FF") == b((15,15))
119
+ True
120
+
121
+ >>> base(0.1, 3, 10, string=True)
122
+ '0.[3]'
123
+
124
+ Recurring digits
125
+ ~~~~~~~~~~~~~~~~
126
+
127
+ Recurring digits at the end of a fractional part will be enclosed by "["
128
+ and "]" in both string and tuple representation. This behavior can be
129
+ turned off by setting the recurring argument of base or BaseConverter
130
+ object to False.
131
+
132
+ ::
133
+
134
+ >>> base("0.1", 3, 10, string=True)
135
+ '0.[3]'
136
+ >>> base("0.1", 3, 10, string=True, recurring=False)
137
+ '0.3333333333'
138
+
139
+ Max fractional depth
140
+ ~~~~~~~~~~~~~~~~~~~~
141
+
142
+ Integer parts are always of arbitrary size. Fractional depth (number of
143
+ digits) can must be specified by setting the max\_depth argument of base
144
+ or a BaseConverter object (default 10).
145
+
146
+ ::
147
+
148
+ >>> base("0.2", 10, 8)
149
+ (0, '.', 1, 4, 6, 3, 1, 4, 6, 3, 1, 4)
150
+ >>> base("0.2", 10, 8, max_depth=1)
151
+ (0, '.', 1)
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,107 @@
1
+ import QtQuick
2
+ import QtQuick.Controls
3
+ import QtQuick.Layouts
4
+
5
+ Item {
6
+ id: buttonRow
7
+ property string text1: "1"
8
+ property string text2: "2"
9
+ property string text3: "3"
10
+ property string text4: "4"
11
+ property string text5: "5"
12
+ property string text6: "6"
13
+ property bool enable1: true
14
+ property bool enable2: true
15
+ property bool enable3: true
16
+ property bool enable4: true
17
+ property bool enable5: true
18
+ property bool enable6: true
19
+ signal buttonPressed(text: string)
20
+ property color color1: "#333333"
21
+ property color colorText1: "#ffffff"
22
+ property color color2: "#333333"
23
+ property color colorText2: "#ffffff"
24
+ property color color3: "#333333"
25
+ property color colorText3: "#ffffff"
26
+ property color color4: "#333333"
27
+ property color colorText4: "#ffffff"
28
+ property color color5: "#333333"
29
+ property color colorText5: "#ffffff"
30
+ property color color6: "#333333"
31
+ property color colorText6: "#ffffff"
32
+ RowLayout {
33
+ anchors.fill: parent
34
+ Button {
35
+ id: button1
36
+ visible: enable1
37
+ Layout.fillWidth: true
38
+ Layout.fillHeight: true
39
+ text: buttonRow.text1
40
+ onClicked: buttonPressed(text)
41
+ palette {
42
+ button: color1
43
+ buttonText: colorText1
44
+ }
45
+ }
46
+ Button {
47
+ id: button2
48
+ visible: enable2
49
+ Layout.fillWidth: true
50
+ Layout.fillHeight: true
51
+ text: buttonRow.text2
52
+ onClicked: buttonPressed(text)
53
+ palette {
54
+ button: color2
55
+ buttonText: colorText2
56
+ }
57
+ }
58
+ Button {
59
+ id: button3
60
+ visible: enable3
61
+ Layout.fillWidth: true
62
+ Layout.fillHeight: true
63
+ text: buttonRow.text3
64
+ onClicked: buttonPressed(text)
65
+ palette {
66
+ button: color3
67
+ buttonText: colorText3
68
+ }
69
+ }
70
+ Button {
71
+ id: button4
72
+ visible: enable4
73
+ Layout.fillWidth: true
74
+ Layout.fillHeight: true
75
+ text: buttonRow.text4
76
+ onClicked: buttonPressed(text)
77
+ palette {
78
+ button: color4
79
+ buttonText: colorText4
80
+ }
81
+ }
82
+ Button {
83
+ id: button5
84
+ visible: enable5
85
+ Layout.fillWidth: true
86
+ Layout.fillHeight: true
87
+ text: buttonRow.text5
88
+ onClicked: buttonPressed(text)
89
+ palette {
90
+ button: color5
91
+ buttonText: colorText5
92
+ }
93
+ }
94
+ Button {
95
+ id: button6
96
+ visible: enable6
97
+ Layout.fillWidth: true
98
+ Layout.fillHeight: true
99
+ text: buttonRow.text6
100
+ onClicked: buttonPressed(text)
101
+ palette {
102
+ button: color6
103
+ buttonText: colorText6
104
+ }
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,5 @@
1
+ from baseconvert.baseconvert import BaseConverter
2
+ from baseconvert.baseconvert import base
3
+
4
+ import pkg_resources
5
+ __version__ = pkg_resources.require("baseconvert")[0].version
@@ -0,0 +1,51 @@
1
+ from baseconvert import base
2
+
3
+
4
+ import sys
5
+ import argparse
6
+
7
+
8
+ def main():
9
+ """
10
+ Main entry point for running baseconvert as a command.
11
+
12
+ Examples:
13
+
14
+ $ python -m baseconvert -n 0.5 -i 10 -o 20 -s True
15
+ 0.A
16
+
17
+ $ echo 3.1415926 | python -m baseconvert -i 10 -o 16 -d 3 -s True
18
+ 3.243
19
+ """
20
+ # Parse arguments
21
+ parser = argparse.ArgumentParser(description="Convert rational numbers between bases.")
22
+ parser.add_argument("-n", "--number", default=None,
23
+ help="The number to convert as a string, else stdin used.")
24
+ parser.add_argument("-i", "--input-base", default=10,
25
+ help="The input base (default 10).")
26
+ parser.add_argument("-o", "--output-base", default=10,
27
+ help="The output base (default 10).")
28
+ parser.add_argument("-d", "--max_depth", default=10, type=int,
29
+ help="The maximum fractional digits (default 10).")
30
+ parser.add_argument("-r", "--recurring", default=True, type=bool,
31
+ help="Boolean, if True will attempt to find recurring decimals (default True).")
32
+ parser.add_argument("-s", "--string", type=bool,
33
+ help="Boolean, if True will output number as String, else as tuple (default False).")
34
+ args = parser.parse_args()
35
+
36
+ args.input_base = float(args.input_base)
37
+ args.output_base = float(args.output_base)
38
+ if args.input_base == int(args.input_base):
39
+ args.input_base = int(args.input_base)
40
+ if args.output_base == int(args.output_base):
41
+ args.output_base = int(args.output_base)
42
+ if (args.number):
43
+ return base(args.number, args.input_base, args.output_base, string=args.string, max_depth=args.max_depth, recurring=args.recurring)
44
+ elif not sys.stdin.isatty():
45
+ return base(sys.stdin.read().strip(), args.input_base, args.output_base, string=args.string, max_depth=args.max_depth, recurring=args.recurring)
46
+ else:
47
+ from .gui import main
48
+ main()
49
+
50
+ if __name__ == "__main__":
51
+ print(main())