Skip to content
Snippets Groups Projects
Commit d5e69f0a authored by Loïc Correnson's avatar Loïc Correnson Committed by Virgile Prevosto
Browse files

[lib] bin & hex pretty printers for Integer

parent 85989c7c
No related branches found
No related tags found
No related merge requests found
--------------------------------------------------
Dec. 0
Hex. 0x0000
Bin. 0b00000000
--------------------------------------------------
Dec. 1
Hex. 0x0001
Bin. 0b00000001
--------------------------------------------------
Dec. -1
Hex. 1xFFFF
Bin. 1b11111111
--------------------------------------------------
Dec. 2
Hex. 0x0002
Bin. 0b00000010
--------------------------------------------------
Dec. -2
Hex. 1xFFFE
Bin. 1b11111110
--------------------------------------------------
Dec. 5
Hex. 0x0005
Bin. 0b00000101
--------------------------------------------------
Dec. -5
Hex. 1xFFFB
Bin. 1b11111011
--------------------------------------------------
Dec. 9
Hex. 0x0009
Bin. 0b00001001
--------------------------------------------------
Dec. -9
Hex. 1xFFF7
Bin. 1b11110111
--------------------------------------------------
Dec. 16
Hex. 0x0010
Bin. 0b00010000
--------------------------------------------------
Dec. -16
Hex. 1xFFF0
Bin. 1b11110000
--------------------------------------------------
Dec. 127
Hex. 0x007F
Bin. 0b01111111
--------------------------------------------------
Dec. -127
Hex. 1xFF81
Bin. 1b10000001
--------------------------------------------------
Dec. 128
Hex. 0x0080
Bin. 0b10000000
--------------------------------------------------
Dec. -128
Hex. 1xFF80
Bin. 1b10000000
--------------------------------------------------
Dec. 255
Hex. 0x00FF
Bin. 0b11111111
--------------------------------------------------
Dec. -255
Hex. 1xFF01
Bin. 1b00000001
--------------------------------------------------
Dec. 4279173135
Hex. 0xFF0F000F
Bin. 0b11111111000011110000000000001111
--------------------------------------------------
Dec. -4279173135
Hex. 1x00F0FFF1
Bin. 1b00000000111100001111111111110001
--------------------------------------------------
Dec. 386334727
Hex. 0x17070007
Bin. 0b00010111000001110000000000000111
--------------------------------------------------
Dec. -386334727
Hex. 1xE8F8FFF9
Bin. 1b11101000111110001111111111111001
--------------------------------------------------
[kernel] Parsing tests/misc/pp_bin_hex.i (no preprocessing)
/* run.config
CMD: @frama-c@ -no-autoload-plugins
OPT: -load-script tests/misc/pp_bin_hex.ml
*/
let pp_dec fmt z = Integer.pretty ~hexa:false fmt z
let pp_hex fmt z = Integer.pp_hex ~nbits:16 fmt z
let pp_bin fmt z = Integer.pp_bin ~nbits:8 fmt z
let hrule () =
Format.printf "--------------------------------------------------@."
let testcase z =
begin
hrule () ;
Format.printf "Dec. %a@." pp_dec z ;
Format.printf "Hex. %a@." pp_hex z ;
Format.printf "Bin. %a@." pp_bin z ;
end
let () =
begin
List.iter
(fun z ->
testcase z ;
if not (Integer.equal z Integer.zero) then
testcase (Integer.neg z)
) [
Integer.of_string "0" ;
Integer.of_string "1" ;
Integer.of_string "2" ;
Integer.of_string "5" ;
Integer.of_string "9" ;
Integer.of_string "16" ;
Integer.of_string "127" ;
Integer.of_string "128" ;
Integer.of_string "0xFF" ;
Integer.of_string "0xFF0F000F" ;
Integer.of_string "0x17070007" ;
] ;
hrule () ;
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment