diff options
-rw-r--r-- | utils/nativeint.ml | 9 | ||||
-rw-r--r-- | utils/nativeint.mli | 3 |
2 files changed, 12 insertions, 0 deletions
diff --git a/utils/nativeint.ml b/utils/nativeint.ml index 6332b7b24..43a7f6904 100644 --- a/utils/nativeint.ml +++ b/utils/nativeint.ml @@ -52,3 +52,12 @@ let to_string n = (if n.msw >= 0 then "" else "-") ^ (if q > 0 then string_of_int q else "") ^ string_of_int (r * 2 + a.lsb) + +let to_hexa_string n = + let a = if n.msw >= 0 then n else sub (from 0) n in + let q = a.msw lsr 3 in + let r = a.msw land 0x7 in + Printf.sprintf "%s0x%x%x" + (if n.msw >= 0 then "" else "-") + q + (r * 2 + a.lsb) diff --git a/utils/nativeint.mli b/utils/nativeint.mli index 5063c6f87..76ea7de83 100644 --- a/utils/nativeint.mli +++ b/utils/nativeint.mli @@ -38,3 +38,6 @@ val cmp: t -> int -> int (* [cmp n1 i2] is [compare n1 (from i2)]. *) val to_string: t -> string (* Return the signed decimal representation of a native integer. *) +val to_hexa_string: t -> string + (* Return the signed hexadecimal representation of a native integer, + in 0x notation. *) |