How to use signed bitconcat and bitsliceget?

조회 수: 2(최근 30일)
Mustafa Tüzün
Mustafa Tüzün 2019년 1월 15일
편집: Kiran Kintali 2022년 8월 15일
Hello,
i am using Matlab for my Bachelor and i have got a problem with bitconcat and bitslice. If i concat or slice fi objects they are automatically unsigned. Does anyone know how to use bitconcat or bitslice signed?
All = bitconcat(fi(-100,1,16,0),fi(5,1,16,0));
y1 = bitsliceget(cast_to_fi(All),16,1);
y2 = bitsliceget(cast_to_fi(All),32,17);
y1 =
5
DataTypeMode: Fixed-point: binary point scaling
Signedness: Unsigned
WordLength: 16
FractionLength: 0
y2 =
65436
DataTypeMode: Fixed-point: binary point scaling
Signedness: Unsigned
WordLength: 16
FractionLength: 0
I do not know how to solve this. i need y2 = -100 there. Is there any way to use bitconcat/bitslice signed? Or any way to solve this problem.
Yours sincerely
Mustafa
  댓글 수: 1
Slava Razumov
Slava Razumov 2020년 9월 2일
https://www.mathworks.com/matlabcentral/answers/226225-keep-sign-when-using-bitsliceget

댓글을 달려면 로그인하십시오.

답변(1개)

Kiran Kintali
Kiran Kintali 2022년 8월 15일
편집: Kiran Kintali 2022년 8월 15일
The bitwise operator functions such as bitsliceget and bitconcat operate on underlying stored integer bits.
Once bitwise operations of slice/concat are performed, you should be able to update the result using reinterpretcast function to the proper type of your choice to see the underlying real world value.
>> T = numerictype(1,16,0);
>> A = bitconcat(fi(-100, T), fi(5, T));
>> y1 = bitsliceget(A, 16, 1);
>> y2 = bitsliceget(A, 32, 17);
>> y1_rwv = reinterpretcast(y1, T);
>> y2_rwv = reinterpretcast(y2, T);
>> y1_rwv, y2_rwv
y1_rwv =
5
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 0
y2_rwv =
-100
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 0
>>

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by