How to use signed bitconcat and bitsliceget?

11 visualizaciones (últimos 30 días)
Mustafa Tüzün
Mustafa Tüzün el 15 de En. de 2019
Editada: Kiran Kintali el 15 de Ag. de 2022
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 comentario
Slava Razumov
Slava Razumov el 2 de Sept. de 2020
https://www.mathworks.com/matlabcentral/answers/226225-keep-sign-when-using-bitsliceget

Iniciar sesión para comentar.

Respuestas (1)

Kiran Kintali
Kiran Kintali el 15 de Ag. de 2022
Editada: Kiran Kintali el 15 de Ag. de 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
>>

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by