How to use signed bitconcat and bitsliceget?
7 views (last 30 days)
Show older comments
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 Comment
Slava Razumov
on 2 Sep 2020
https://www.mathworks.com/matlabcentral/answers/226225-keep-sign-when-using-bitsliceget
Answers (1)
Kiran Kintali
on 15 Aug 2022
Edited: Kiran Kintali
on 15 Aug 2022
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
>>
0 Comments
See Also
Categories
Find more on Functions for Programming and Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!