How to use signed bitconcat and bitsliceget?
3 次查看(过去 30 天)
显示 更早的评论
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
2020-9-2
https://www.mathworks.com/matlabcentral/answers/226225-keep-sign-when-using-bitsliceget
回答(1 个)
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
>>
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Create Fixed-Point Objects in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!