Aditya Agrawal
Aditya Agrawal

Reputation: 167

How to do a hexadecimal multiplication in OCaml?

How should I do a hexademical calculation in OCaml? For example I want to multiply 0x0a and 0xff.

What should I do?

Upvotes: 2

Views: 321

Answers (2)

Pascal Cuoq
Pascal Cuoq

Reputation: 80325

For the whole package, use Printf.printf "%x\n" (0x0a * 0xff).

The %x conversion prints in hexadecimal, and integer constants in the program can be typed in hexadecimal with the 0x prefix.

Example:

$ rlwrap ocaml
        OCaml version 4.01.0

# Printf.printf "0x%x\n" (0x0a * 0xff);;
0x9f6

Upvotes: 2

ivg
ivg

Reputation: 35280

0x0a * 0xff

Hexadecimal is just yet another notation, not another algebra.

Upvotes: 2

Related Questions