bitget function

5 次查看(过去 30 天)
Aseel H
Aseel H 2012-3-16
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'

回答(1 个)

Walter Roberson
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
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
Aseel H
Aseel H 2012-3-16
I run your code it true but my code don't work
so, can I send my file for you

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by