bitset function does not work with numbers more than 2^32-1 or if pos is more than 32
Reported by Stanislav Kroter
Bug description:
The bitset function returns wrong result if an input value is more than 2^32-1 or if pos is more than 32.
Error log:
How to reproduce the bug:
For case when input value is more than 2^32-1. C should be equal to A.
-->A = 2^33-1;B = bitset(A,13,0);C = bitset(B,13,1);dec2bin([A;B;C])
ans =
!111111111111111111111111111111111 !
! !
!000000000000000000000000000000000 !
! !
!000000000000000000001000000000000 !
For case when pos is more than 32.
-->A = 2^32-1;B = bitset(A,33,0);C = bitset(B,33,1);dec2bin([A;B;C;2^34-1])
ans =
!0011111111111111111111111111111111 !
! !
!0011111111111111111111111111111111 !
! !
!0011111111111111111111111111111111 !
! !
!1111111111111111111111111111111111 !
As you can see B is wrong and C is equal to A because bitset does not work properly.
Other information: