Community discussions

MikroTik App
 
bobwalker
just joined
Topic Author
Posts: 23
Joined: Sun Apr 03, 2011 6:07 am

How to covert int to hex type value and save it in a string?

Fri Dec 16, 2011 5:23 pm

How to covert int to hex type value and save it in a string?
It is like that Routeros doest have the script function (but have toarray,tobool,totime etc.).
Doesnt truely RouterOS have the script function coverting int to hex ??
I need it in a layer7filter-script.
Thanks!
Last edited by bobwalker on Fri Dec 16, 2011 5:39 pm, edited 1 time in total.
 
User avatar
TealFrog
just joined
Posts: 23
Joined: Sun Oct 02, 2011 11:56 am

Re: How to covert int to hex type value and save it in a str

Sun Dec 18, 2011 11:09 am

I don't recall where I found this, but it should help...
# $dec has decimal value to convert
:local dec 3735928559
# $hexdigit set this to number of hex digits (max) you want
:local hexdigit 8
# $hex is string containing hex value
:local hex ""
:for i from=0 to=(4*($hexdigit-1)) step=4 do={
   :set hex ([:pick "0123456789ABCDEF" (($dec>>$i)&0xf) ((($dec>>$i)&0xf)+1)].$hex)
}
:log info ("0x".$hex)
TealFrog

Who is online

Users browsing this forum: Google [Bot], martix77, sindy, willianwrm and 68 guests