bitget function

5 views (last 30 days)
Aseel H
Aseel H on 16 Mar 2012
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'

Answers (1)

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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!