# How to convert float to a hex string

**URL:** https://discuss.ocaml.org/t/how-to-convert-float-to-a-hex-string/2916
**Category:** Learning
**Tags:** announce
**Created:** [November 19, 2018, 1:04pm UTC](https://discuss.ocaml.org/t/how-to-convert-float-to-a-hex-string/2916 "2018-11-19T13:04:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kiukotsu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/kiukotsu/32/1300_2.png) [@kiukotsu](https://discuss.ocaml.org/u/kiukotsu)
#### Post date: [November 19, 2018, 1:04pm UTC](https://discuss.ocaml.org/t/how-to-convert-float-to-a-hex-string/2916/1 "2018-11-19T13:04:25Z")

</div>

Example:

```auto
input: 2.33
output: 0x4002 a3d7 0a3d 70a4

```

it seems that `fprintf` doesn’t have the kind of format.

---

<div class="post-metadata">

### Author: ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)
#### Post date: [November 19, 2018, 1:20pm UTC](https://discuss.ocaml.org/t/how-to-convert-float-to-a-hex-string/2916/2 "2018-11-19T13:20:26Z")

</div>

You can use `Int64.bits_of_float` to get a 64-bit representation which you then can print any way you like.
