How to find One's complement of floating point variable ?

Hi,
I used Simulink Bitwise Not operator to find the one's complement of uint8 type variable.
Now I want to find one's complement of float variable (double) using simulink.
Can you please help me on how to perform the task.
Thank you

2 件のコメント

James Tursa
James Tursa 2021 年 2 月 5 日
What does a 1's complement of a floating point bit pattern even mean to you? How do you intend to use this result?
kintali narendra
kintali narendra 2021 年 2 月 5 日
編集済み: kintali narendra 2021 年 2 月 5 日
I need to convert float variable to binary number and then find one's complement of that, covert it into float variable again.
I am using it for redundancy validation.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 5 日

0 投票

typecast to uint64, take the one's complement, typecast back.
Caution: 1's complement of 0.0 is NaN.

9 件のコメント

kintali narendra
kintali narendra 2021 年 2 月 5 日
the simulink model has run successfully but the answer is same for every number.
Walter Roberson
Walter Roberson 2021 年 2 月 5 日
you used a Convert block which is not appropriate.
You need to use a MATLAB Function Block.
function out = fcn(u)
out = zeros(size(u));
out = typecast(bitxor(typecast(u, 'uint64'), 0xffffffffffffffffu64), 'double');
kintali narendra
kintali narendra 2021 年 2 月 7 日
Thank you. it worked.
Paul
Paul 2021 年 2 月 7 日
My version (2019a) doesn't support Walter's code. What result should be shown in the Display block when the input is 23?
Walter Roberson
Walter Roberson 2021 年 2 月 8 日
function out = fcn(u)
out = zeros(size(u));
out = typecast(bitxor(typecast(u, 'uint64'), intmax('uint64')), 'double');
kintali narendra
kintali narendra 2021 年 2 月 8 日
編集済み: kintali narendra 2021 年 2 月 8 日
Hi Paul, these are my answers.
For 23 it is -0.1953
For 93 it is -0.04834
Paul
Paul 2021 年 2 月 8 日
When the input is 23, do you want the Display block to show -0.1953? In other words, is -0.1953 the correct answer for 23 with respect to what you are trying accomplish?
From what you've described, I thought the goal was to get the decimal representation of the one's complement of the binary representation of 23. Is that what -0.1953 is?
kintali narendra
kintali narendra 2021 年 2 月 8 日
yes, I want decimal representation of the one's complement.
The function which Walter recommened worked.
Walter Roberson
Walter Roberson 2021 年 2 月 8 日
@Paul note in particular they wanted the one's complement of the binary representation of double precision numbers, not of an integer data type.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by