forked from ALLZ/hex-bin_system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdec_to_hex.py
More file actions
22 lines (19 loc) · 746 Bytes
/
dec_to_hex.py
File metadata and controls
22 lines (19 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sublime
import sublime_plugin
class DecToHexCommand(sublime_plugin.TextCommand):
MAX_STR_LEN = 20
def run(self, edit):
v = self.view
reglist = list(v.sel())
for i in range(0, len(reglist)):
dec = v.substr(v.sel()[i])
dec = dec.strip()
if dec.isdigit():
v.replace(edit, v.sel()[i], '{0:X}'.format(int(dec)))
else:
if len(dec) > self.MAX_STR_LEN:
logMsg = dec[0:self.MAX_STR_LEN] + "..."
else:
logMsg = dec
sublime.status_message("\"%s\" isn't a decimal number!" % logMsg)
sublime.error_message("\"%s\" isn't a decimal number!" % logMsg)