-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path003_operators.rb
More file actions
executable file
·67 lines (51 loc) · 917 Bytes
/
003_operators.rb
File metadata and controls
executable file
·67 lines (51 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#003_number_operator
puts "\n\tOperators\n\n"
#Random
a = 10 * rand
puts "Random:\t 10 * rand = #{a}"
#Add
a = 10 + 2
puts "Add:\t 10 + 2 = #{a}"
#Sub
a = 10 - 2
puts "Sub:\t 10 - 2 = #{a}"
#Multi
a = 10 * 2
puts "Multi:\t 10 * 2 = #{a}"
#Div
a = 10 / 2
puts "Div:\t 10 / 2 = #{a}"
#Mod
a = 10 % 2
puts "Mod:\t 10 % 2 = #{a}"
#Exp
a = 10 ** 2
puts "dand:\t 10 ** 2 = #{a}"
#Logic Operation
puts "\n\tLogic\n\n"
#AND
a = 10 & 2
puts "AND:\t 10 & 2 = #{a}"
puts "1010","&&&&","0010","====","0010"
puts
#OR
a = 10 | 2
puts "OR:\t 10 | 2 = #{a}"
puts "1010","||||","0010","====","1010"
puts
#XOR
a = 10 ^ 2
puts "XOR:\t 10 ^ 2 = #{a}"
puts "1010","^^^^","0010","====","1000"
puts
#shift-left
a = 10 << 2
puts "shift-left:\t 10 << 2 = #{a}"
puts "001010","<<<<","010100","<<<<","101000"
puts
#shift-right
a = 10 >> 2
puts "shift-right:\t 10 >> 2 = #{a}"
puts "1010",">>>>","0101",">>>>","0010"
puts
puts