How must i read te vb code: CheckBox5.Checked = (i >> 1) And

hi,

I found this code in the demoproject from the K8055 kit:

CheckBox5.Checked = (i >> 1) And 1 (see in red to reveal in the complete code)
Can someone explain how to ‘read’ this piece of code? I don’t understand this way!?

Thanx!

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim i As Integer Dim Data1 As Integer Dim Data2 As Integer Timer1.Enabled = False i = ReadAllDigital [color=#FF0000]CheckBox4.Checked = i And 1 CheckBox5.Checked = (i >> 1) And 1 CheckBox6.Checked = (i >> 2) And 1 CheckBox7.Checked = (i >> 3) And 1 CheckBox8.Checked = (i >> 4) And 1[/color] ReadAllAnalog(Data1, Data2) VScrollBar3.Value = 255 - Data1 VScrollBar4.Value = 255 - Data2 Label6.Text = CStr(Data1) Label7.Text = CStr(Data2) TextBox1.Text = CStr(ReadCounter(1)) TextBox2.Text = CStr(ReadCounter(2)) Timer1.Enabled = True End Sub

The digital input value is i.
Each of the lowest 5 bits are tested.
The lowest bit is tested by this:

CheckBox4.Checked = i And 1The And operation with 1 masks out all other bits except the lowest one.
If the lowest bit of i is 1 then the result of the And operation is true and the CheckBox4 will be Checked.

Other bits of the digital input value are checked by first shifting the bits right.
In this case i is shifted right 1 bit. This way the second lowest bit can be checked.

CheckBox5.Checked = (i >> 1) And 1

Here the third lowest bit will be checked:

CheckBox6.Checked = (i >> 2) And 1

etc.

CheckBox7.Checked = (i >> 3) And 1 CheckBox8.Checked = (i >> 4) And 1

For more details about the >> operator please see:
http://msdn.microsoft.com/en-us/library/dezyht83.aspx#Y824

Thanx VEL255…this helps a lot! I never use / see that >> operator before.

And also i see, i must convert the integer to a binary to understand…THANX A LOT!!

Telly