Convert the hexadecimal representation of a binary double-precision number back into a double

How can I convert a double-precision hexadecimal back into a double?
That is, given s, created from the double x as such:
s = sprintf('%bx',x)
How can I recover x?

 Accepted Answer

>> x=rand
x =
0.126986816293506
>> s = sprintf('%bx',x)
s =
3fc0411a9f807b7c
>> y=hex2num(s)
y =
0.126986816293506

1 Comment

That's it! I tried this and thought it wasn't working, but I had previously set "format hex". Thanks.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!