MATLAB Answers

How to set individual bits in 64-bit double-precision floating number

17 views (last 30 days)
Kevin
Kevin on 4 May 2018
Commented: Kevin on 5 May 2018
Hi everyone,
I am wondering if it is possible to set individual bits in 64-bit double-precision floating number in MATLAB.
I know that I can use "format hex" to read the bits. But how can I set it?
Thanks Kevin

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 5 May 2018
Example:
typecast(bitset(typecast(pi,'uint64'),53,1),'double')
Bit numbering is 64 for the most significant bit, down to 1 for the least significant bit.
As the IEEE 754 floating point representation is being altered, the change I made here of effectively adding 1 to the exponent resulting in doubling the result (because IEEE 754 has binary representation, not decimal representation.)

  3 Comments

Kevin
Kevin on 5 May 2018
Hi Walter,
Excellent. This is exactly what I am looking for.
Side question. Were you working for CIBC investment? Long time ago I think there was a Walter (if my memory is right) very active in the MATLAB newsgroup and working for CIBC investment.
Thanks Kevin
Walter Roberson
Walter Roberson on 5 May 2018
I have never worked for CIBC or any finance company.
I find a record of Michael Robbins in comp.soft-sys.matlab who worked for CIBC. Looks like he had about 75-ish posts. My active time on comp.soft-sys.matlab did not overlap with him.
Kevin
Kevin on 5 May 2018
You are correct. I was thinking about Michael Robbins.
Thanks again for your help.

Sign in to comment.

More Answers (0)

Tags