필터 지우기
필터 지우기

Keep sign when using bitsliceget()

조회 수: 6 (최근 30일)
Lennart
Lennart 2015년 7월 1일
편집: Krishnan Gopal 2019년 7월 24일
Hi there,
I want to extract 8 bits from a 16bit fixed point number using bitsliceget(). Unfortunately the result is always an unsigned variable, which is not what I want.
Here is a little example:
x = fi(-0.12835,true, 16,10);
x.bin
ans = 1111111101111101
y = bitsliceget(x,9,2)
ans = 190
DataTypeMode: Fixed-point: binary point scaling
Signedness: Unsigned
WordLength: 8
FractionLength: 0
y.bin
ans = 10111110
bitsliceget(x,9,2) actually does exactly what I want it to but I just can't get y to become a signed variable without recasting and therefore changing the binary representation.
Any help would be highly appreciated.
Thanks it advance for taking the time!
Regards,
Len

답변 (1개)

Krishnan Gopal
Krishnan Gopal 2019년 7월 24일
편집: Krishnan Gopal 2019년 7월 24일
Hi
The result of bitsliceget is always interpreted as an unsigned type, so you can use the 'reinterpretcast' function to re-evaluate it as a numeric signed type. In your case, the you should cast it to a signed numerictype with 8 bits as shown:
y = reinterpretcast(bitsliceget(x,9,2), numerictype(1,8,0));
regards
Krishnan

카테고리

Help CenterFile Exchange에서 Fixed-Point Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by