- procedure hex(s)
- local a,c
- a := 0
- every c := !map(s) do
- a := ior(find(c,"0123456789abcdef") - 1, ishift(a,4)) | fail
- return a
- end
- #
- #
- procedure hexstring(i,n,lowercase)
- local s, hexchars, sign
- i := integer(i) | runerr(101, i)
- sign := ""
- if i = 0 then s := "0"
- else {
- if /n & i < 0 then {
- sign := "-"
- i := -i
- }
- hexchars := if \lowercase
- then "0123456789abcdef"
- else "0123456789ABCDEF"
- s := ""
- until i = (0 | -1) do {
- s := hexchars[iand(i,15) + 1] || s
- i := ishift(i,-4)
- }
- }
- if \n > *s then s := right(s,n,if i >= 0 then "0" else hexchars[16])
- return sign || s
- end
Raw Paste