bitwiseCalc 1.1.1 → 1.3.2
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 +34 -21
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd231233410a0cbaf9895e9af65a59a324fd93ef
|
4
|
+
data.tar.gz: 8f53ece11b4d2f48e03b1b0ea60137bc5cf8d210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1fe010d775788ee75fb03cd817a044d3fe1cd03a30ee6e9d8a08f310a403c883c126274e099aead4de766633fd0ed068b5d0862376fb3b1a890a1d944d71b38
|
7
|
+
data.tar.gz: 8741f577deb99e3e43afb90eb4a9a837e4714f69c477b1a93e96848bd18a62f045c8fe874aa529c7b83bc143a7370b5f98f5edc8c74bb7367579c06b661d841d
|
data/lib/bitwiseCalc
CHANGED
@@ -4,7 +4,7 @@
|
|
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-06-12
|
7
|
+
# @Last Modified time: 2015-06-30 12:22:35
|
8
8
|
require 'colorize'
|
9
9
|
class BoolCalc
|
10
10
|
def print_all_radix(num)
|
@@ -64,9 +64,10 @@ class BoolCalc
|
|
64
64
|
if (@operation == nil)
|
65
65
|
abort ("ERROR, Expected Operation".red)
|
66
66
|
end
|
67
|
-
#not
|
68
|
-
#rad can
|
69
|
-
#
|
67
|
+
#not operation is unary
|
68
|
+
#rad can be either unary or binary
|
69
|
+
#following logic avoids running a binary operation when user entered
|
70
|
+
#only one number
|
70
71
|
operation_restriction = (@operation != "NOT" && @operation != "RAD")
|
71
72
|
if ((operation_restriction && (@y == nil || @y == 0)) || (@x == nil || @x == 0))
|
72
73
|
abort("ERROR, Missing Numbers for Operation:\t#{@operation}".red)
|
@@ -134,9 +135,9 @@ class BoolCalc
|
|
134
135
|
x XOR y
|
135
136
|
Displays x XOR y
|
136
137
|
x SHR y
|
137
|
-
Displays x Shifted Right
|
138
|
+
Displays x Shifted Right y times
|
138
139
|
x SHL y
|
139
|
-
Displays x Shifted Left
|
140
|
+
Displays x Shifted Left y times
|
140
141
|
x ROR y
|
141
142
|
Displays x Rotated Right y times
|
142
143
|
x ROL y
|
@@ -159,19 +160,31 @@ class BoolCalc
|
|
159
160
|
#outputs num in binary form
|
160
161
|
#adds a space every 4 bits
|
161
162
|
def print_nice_binary(num)
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
163
|
+
if num <= (2**31)
|
164
|
+
puts "\t32 Bit Format".yellow
|
165
|
+
print "\t"
|
166
|
+
31.downto(0) do |n|
|
167
|
+
print num[n]
|
168
|
+
if (n%4 == 0); print " " end
|
169
|
+
end
|
167
170
|
end
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
171
|
+
if num <= (2**63)
|
172
|
+
puts "\n\t64 Bit Format".yellow
|
173
|
+
print "\t"
|
174
|
+
63.downto(0) do |n|
|
175
|
+
print num[n]
|
176
|
+
if (n%4 == 0); print " " end
|
177
|
+
end
|
178
|
+
else
|
179
|
+
puts "\n\t128 Bit Format".yellow
|
180
|
+
print "\t"
|
181
|
+
127.downto(0) do |n|
|
182
|
+
if (n == 63); print"\n\t" end
|
183
|
+
print num[n]
|
184
|
+
if (n%4 == 0); print " " end
|
185
|
+
end
|
173
186
|
end
|
174
|
-
puts
|
187
|
+
puts
|
175
188
|
end
|
176
189
|
#converts an integer to a binary array
|
177
190
|
def int_to_binary_arr()
|
@@ -181,13 +194,12 @@ class BoolCalc
|
|
181
194
|
end
|
182
195
|
end
|
183
196
|
def ror()
|
197
|
+
arr_tail = @bit64_array_x.length-2
|
184
198
|
for i in 1..@y
|
185
199
|
#save least significant bit(end of array)
|
186
200
|
lsb = @bit64_array_x[-1]
|
187
|
-
for j in 0..
|
201
|
+
for j in 0..arr_tail
|
188
202
|
if j == 0
|
189
|
-
#save next elem(right shift)
|
190
|
-
#assign next element in the array to the current element
|
191
203
|
tmp1 = @bit64_array_x[j+1]
|
192
204
|
@bit64_array_x[j+1] = @bit64_array_x[j]
|
193
205
|
end
|
@@ -201,10 +213,11 @@ class BoolCalc
|
|
201
213
|
end
|
202
214
|
end
|
203
215
|
def rol()
|
216
|
+
arr_tail = @bit64_array_x.length-2
|
204
217
|
for i in 1..@y
|
205
218
|
#save most significant bit(beginning of array)
|
206
219
|
msb = @bit64_array_x[0]
|
207
|
-
for j in 0..
|
220
|
+
for j in 0..arr_tail
|
208
221
|
#assign next element in array to current element in array
|
209
222
|
@bit64_array_x[j] = @bit64_array_x[j+1]
|
210
223
|
end
|
metadata
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitwiseCalc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.2
|
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-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.7.7
|
20
|
-
- -
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.7.7
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.7.7
|
30
|
-
- -
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.7.7
|
33
33
|
description: A simple BitWise Calculator that can peform arithmetic
|
@@ -48,17 +48,17 @@ require_paths:
|
|
48
48
|
- lib
|
49
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
|
-
- -
|
56
|
+
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.
|
61
|
+
rubygems_version: 2.2.3
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: BitWise Calculator
|