bitget function

4 Ansichten (letzte 30 Tage)
Aseel H
Aseel H am 16 Mär. 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'

Antworten (1)

Walter Roberson
Walter Roberson am 16 Mär. 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 Kommentare
Walter Roberson
Walter Roberson am 16 Mär. 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 am 16 Mär. 2012
I run your code it true but my code don't work
so, can I send my file for you

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by