bitget function
4 次查看(过去 30 天)
显示 更早的评论
I use bitset function to replace LSB by another bit in array
but when extract this LSB by bitget function
the result = null
for example
a = [0 1 0 1];
b = [5 3 8];
c= bitset(b,1,a);
until this no problem
after that in decoding
d = bitget(b,1);
but result of d =[0 0 0 0];
not [0 1 0 1]
so, i need know what the problem in function 'bitget'
0 个评论
回答(1 个)
Walter Roberson
2012-3-16
bitget(b,1) is going to be the same length of b. As b is of length 3, you should not be expecting to get a vector of length 4 as the result.
Your bitset() will also fail because you are trying to set bits for 4 elements out of the 3 element vector b.
3 个评论
Walter Roberson
2012-3-16
Are you sure?
>> b= [5 3 8 4]
b =
5 3 8 4
>> bitget(b,1)
ans =
1 1 0 0
Notice that you stored the result of the bitset() in to "c", but you then try to get those bits back from "b".
>> bitget(bitset([5 3 8 4],1,[0 1 0 1]),1)
ans =
0 1 0 1
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!