MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Aleksander
on 22 May 2013

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

*No products are associated with this question.*

Answer by Matt J
on 22 May 2013

Edited by Matt J
on 22 May 2013

One way,

>> bits=fliplr(num2str(a)-'0'); bits(5)

ans =

1

Show 1 older comment

Matt J
on 25 May 2013

**Thea means that each segment in the 5 segment number coresponds to button, the trick is how to read each segment ??**

Since you have "10101" in string form, you can index each digit in the string directly and convert it to numeric form, which is what I showed you in the solution I proposed. BITGET is not applicable here.

Aleksander
on 25 May 2013

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.

## 1 Comment

## Azzi Abdelmalek (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76693#comment_150411

What is your question?