Finding a bit value ?

조회 수: 3 (최근 30일)
Aleksander
Aleksander 2013년 5월 22일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 22일
What is your question?

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2013년 5월 22일
편집: Matt J 2013년 5월 22일
One way,
>> bits=fliplr(num2str(a)-'0'); bits(5)
ans =
1
  댓글 수: 4
Aleksander
Aleksander 2013년 5월 25일
Thanks, i tested it now and looks to work as i want :) Sine i am a nub can you try to enlighten me how fliplr actualy dose This ? Thanks.
Matt J
Matt J 2013년 5월 25일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by