Finding a bit value ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi. I have a value like a = 10101 this would change after how my program is run, but i will always use 0 or 1. so i consider this binary. now i would like to get the status of bit 5 i.e the first number (closest to the equal sign).
note!: the intention is to have the binary row decied which buttons are displayed in a gui.
this is what i have come up with
%code
for i = 0:4
count = i+1
if (bitget(main_sel2, count)==1)
set(handles.(sprintf('but%d', count))(:),'Visible','on');
else
set(handles.(sprintf('but%d', count))(:),'Visible','off');
end
end
1 Kommentar
Antworten (1)
Matt J
am 22 Mai 2013
Bearbeitet: Matt J
am 22 Mai 2013
One way,
>> bits=fliplr(num2str(a)-'0'); bits(5)
ans =
1
4 Kommentare
Matt J
am 25 Mai 2013
FLIPLR isn't doing anything significant. You posted that you want the indexing order of the bits to run from right to left (bit #5 is the leftmost bit). If you omit FLIPLR, you will be reading from left to right instead.
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!