We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 36f6061 commit f5729b0Copy full SHA for f5729b0
rotator.py
@@ -0,0 +1,27 @@
1
+from __future__ import print_function # PEP 3105
2
+import sys
3
+
4
+# Rotate right: 0b1001 --> 0b1100
5
+ror = lambda val, r_bits, max_bits: \
6
+ ((val & (2**max_bits-1)) >> r_bits%max_bits) | \
7
+ (val << (max_bits-(r_bits%max_bits)) & (2**max_bits-1))
8
9
+max_bits = 32
10
11
+input = int(raw_input("Enter the value you want to check: "))
12
13
+print()
14
+for n in xrange(1, 256):
15
16
+ for i in xrange(0, 31, 2):
17
18
+ rotated = ror(n, i, max_bits)
19
20
+ if(rotated == input):
21
+ print("The number %i can be used as a valid immediate number." % input)
22
+ print("%i ror %x --> %s" % (n, int(str(i), 16), rotated))
23
+ print()
24
+ sys.exit()
25
26
+else:
27
+ print("Sorry, %i cannot be used as an immediate number and has to be split." % input)
0 commit comments