bitwiseCalc 0.0.7 → 1.0.0
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.
- checksums.yaml +4 -4
- data/lib/bitwiseCalc +85 -42
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 359f4a4bae8bf1ea241c9fd891e5d4fedadefb3f
|
4
|
+
data.tar.gz: 2ebc039007a8bb5aff21170ac6b372da65a22390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ad42a008402a0a9e100d638dd8520a11c247bd7ede1ec6b384225e1a4082d83d6106533aee1c7048b0da476157be2a46c57f949af62a0d9c6bbb0010a1b2a8
|
7
|
+
data.tar.gz: 3db8551ed89b036ce5fe39789e22ea8bb1dce8dd81e447ce90e934e39be8f4ca3e099b65dd0df42c3560589f68e4f053a4c2e6091878e74116f9816e664756b0
|
data/lib/bitwiseCalc
CHANGED
@@ -4,24 +4,26 @@
|
|
4
4
|
# @Email: vargash1@wit.edu
|
5
5
|
# @Date: 2015-02-23 10:23:20
|
6
6
|
# @Last Modified by: vargash1
|
7
|
-
# @Last Modified time: 2015-
|
7
|
+
# @Last Modified time: 2015-06-12 17:30:50
|
8
8
|
require 'colorize'
|
9
9
|
class BoolCalc
|
10
10
|
def print_all_radix(num)
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
print "Base 10:\t".yellow; print "#{num.to_s(10)}\n"
|
12
|
+
print "Base 16:\t".yellow; print "#{num.to_s(16)}\n"
|
13
|
+
print "Base 8: \t".yellow; print "#{num.to_s(8)}\n"
|
14
|
+
print "Base 2:\n".yellow
|
14
15
|
print_nice_binary(num)
|
15
16
|
end
|
16
17
|
def execute()
|
17
|
-
|
18
|
+
print "\t---------------------------------------\n".green
|
18
19
|
print_all_radix(@x)
|
19
20
|
if (@y != nil)
|
20
|
-
puts "\t
|
21
|
+
puts "\t---------------------------------------\n".green
|
21
22
|
print_all_radix(@y)
|
22
23
|
end
|
23
|
-
puts "\t-----------------#{@operation}-------------------".yellow
|
24
24
|
case
|
25
|
+
when(@operation == 'RAD')
|
26
|
+
return
|
25
27
|
when (@operation == 'AND')
|
26
28
|
final_result = @x & @y
|
27
29
|
when (@operation == 'OR')
|
@@ -42,25 +44,36 @@ class BoolCalc
|
|
42
44
|
int_to_binary_arr()
|
43
45
|
ror()
|
44
46
|
final_result = (@bit64_array_x.join).to_i(2)
|
45
|
-
when(@operation == '
|
46
|
-
|
47
|
+
when(@operation == 'MUL')
|
48
|
+
final_result = @x * @y
|
49
|
+
when(@operation == 'ADD')
|
50
|
+
final_result = @x + @y
|
51
|
+
when(@operation == 'DIV')
|
52
|
+
final_result = @x / @y
|
53
|
+
when(@operation == 'SUB')
|
54
|
+
final_result = @x - @y
|
55
|
+
when(@operation == 'MOD')
|
56
|
+
final_result = @x % @y
|
57
|
+
when(@operation == 'POW')
|
58
|
+
final_result = @x ** @y
|
47
59
|
end
|
48
|
-
puts "\n\t
|
60
|
+
puts "\n\t-------------#{@operation} Result-----------------".green
|
49
61
|
print_all_radix(final_result)
|
50
62
|
end
|
51
63
|
def check_for_errors()
|
52
64
|
if (@operation == nil)
|
53
|
-
abort ("ERROR,
|
65
|
+
abort ("ERROR, Expected Operation".red)
|
54
66
|
end
|
55
|
-
#not
|
56
|
-
#
|
67
|
+
#not works with one number argument
|
68
|
+
#rad can read in 2 arguments, but can work with 1
|
69
|
+
#if operation is not either and y is nil then the user forgot an argument
|
57
70
|
operation_restriction = (@operation != "NOT" && @operation != "RAD")
|
58
71
|
if ((operation_restriction && @y == nil) || (@x == nil))
|
59
|
-
abort("ERROR,
|
72
|
+
abort("ERROR, Missing Numbers for Operation:\t#{@operation}".red)
|
60
73
|
end
|
61
74
|
end
|
62
75
|
def parse_args()
|
63
|
-
ops = ['NOT','SHR','SHL','AND','OR','XOR','RAD','ROL','ROR']
|
76
|
+
ops = ['NOT','SHR','SHL','AND','OR','XOR','RAD','ROL','ROR','MUL','DIV','ADD','SUB','MOD','POW']
|
64
77
|
if (ARGV.length == 0 || (ARGV[0].upcase) == "-H")
|
65
78
|
print_help()
|
66
79
|
exit
|
@@ -74,8 +87,19 @@ class BoolCalc
|
|
74
87
|
@operation = ops_elem
|
75
88
|
end
|
76
89
|
end
|
77
|
-
#
|
78
|
-
|
90
|
+
#hex val was read
|
91
|
+
when(a == a[/0[xX][0-9a-fA-F]+/])
|
92
|
+
if (@x == nil) ? @x = a.to_i(16): @y = a.to_i(16)
|
93
|
+
end
|
94
|
+
#binary val was read
|
95
|
+
when(a == a[/0[bB][0-1]+/])
|
96
|
+
if (@x == nil) ? @x = a.to_i(2): @y = a.to_i(2)
|
97
|
+
end
|
98
|
+
#octal val was read
|
99
|
+
when(a == a[/0[0-7]+/])
|
100
|
+
if (@x == nil) ? @x = a.to_i(8): @y = a.to_i(8)
|
101
|
+
end
|
102
|
+
#decimal val was read
|
79
103
|
when (is_number(a.to_i))
|
80
104
|
if (@x == nil) ? @x = a.to_i: @y = a.to_i
|
81
105
|
end
|
@@ -87,42 +111,61 @@ class BoolCalc
|
|
87
111
|
return is_num
|
88
112
|
end
|
89
113
|
def print_help()
|
90
|
-
puts """
|
114
|
+
puts """
|
115
|
+
Usage(any of the following are acceptable):
|
116
|
+
\tbitwiseCalc <num> <operation>
|
117
|
+
\tbitwiseCalc <num> <num> <operation>
|
91
118
|
\tbitwiseCalc <num> <operation> <num>\n
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
NOT
|
99
|
-
Displays ~
|
100
|
-
|
101
|
-
Displays
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
119
|
+
|
120
|
+
Passing <num> in a radix other than base10:
|
121
|
+
<base_2_num> = 0b[0-1]
|
122
|
+
<base_8_num> = 0[0-7]
|
123
|
+
<base_16_num> = 0x[0-9a-f]
|
124
|
+
|
125
|
+
NOT x
|
126
|
+
Displays ~x
|
127
|
+
x y RAD
|
128
|
+
Displays x and y in hex, octal, binary, and decimal radixes.
|
129
|
+
1 number argument is sufficient.
|
130
|
+
x AND y
|
131
|
+
Displays x & y
|
132
|
+
x OR y
|
133
|
+
Displays x | y
|
134
|
+
x XOR y
|
135
|
+
Displays x XOR y
|
136
|
+
x SHR y
|
137
|
+
Displays x Shifted Right by y
|
138
|
+
x SHL y
|
139
|
+
Displays x Shifted Left by y
|
140
|
+
x ROR y
|
141
|
+
Displays x Rotated Right y times
|
142
|
+
x ROL y
|
143
|
+
Displays x Rotated Left y times
|
144
|
+
x MUL y
|
145
|
+
Displays x * y
|
146
|
+
x DIV y
|
147
|
+
Displays x divided by y
|
148
|
+
x ADD y
|
149
|
+
Displays x + y
|
150
|
+
x SUB y
|
151
|
+
Displays x - y
|
152
|
+
x MOD y
|
153
|
+
Displays x modulus y
|
154
|
+
x POW y
|
155
|
+
Displays x to the power of y
|
114
156
|
"""
|
115
157
|
exit
|
116
158
|
end
|
117
159
|
#outputs num in binary form
|
160
|
+
#adds a space every 4 bits
|
118
161
|
def print_nice_binary(num)
|
119
|
-
puts "\t32
|
162
|
+
puts "\t32 Bit Format".yellow
|
120
163
|
print "\t"
|
121
164
|
31.downto(0) do |n|
|
122
165
|
print num[n]
|
123
166
|
if (n%4 == 0); print " " end
|
124
167
|
end
|
125
|
-
puts "\n\t64
|
168
|
+
puts "\n\t64 Bit Format".yellow
|
126
169
|
print "\t"
|
127
170
|
63.downto(0) do |n|
|
128
171
|
print num[n]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitwiseCalc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hector Vargas
|
8
8
|
autorequire:
|
9
9
|
bindir: lib
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
- - '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.7.7
|
33
|
-
description: A simple BitWise Calculator
|
33
|
+
description: A simple BitWise Calculator that can peform arithmetic
|
34
34
|
email: hjvargas1213@gmail.com
|
35
35
|
executables:
|
36
36
|
- bitwiseCalc
|