Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Go Back  Xtreme Visual Basic Talk > > > Please Help Me With Remember How To Do This - Senior Moment


Reply
 
Thread Tools Display Modes
  #1  
Old 08-22-2017, 07:19 AM
zunebuggy zunebuggy is offline
Newcomer
 
Join Date: Sep 2010
Posts: 22
Question Please Help Me With Remember How To Do This - Senior Moment


I think I am having a senior moment and have forgotten how to do a VB trick I used to use all the time and cannot find any forum to help my memory.

I used to have value 0 to 15 and I thought I used "AND" as in 2 AND 2 it would return a 1 (or so I thought) because that bit is set. Same thing as 15 AND 2 = 1 because in 1111 the second bit is set. However I am not remembering it quite right because 2 AND 2 actually equals 2.

My program just tests bits 8,4,2 and 1 (four least significant bits) to see if they are set and then my conditions are based simply on a result of 1 or 0. Not 2 or anything higher.

Can someone please help me remember how I used to take a decimal number 0 - 15 and test it for a specific bit 8 (fourth bit),4(third bit),2(second bit) or 1(first bit) and just have it return a 1 or 0? I know I am forgetting something and I hope I explained it well what I am trying to do.

0 AND 0 = 0
0 AND 1 = 0
0 AND 2 = 0
0 AND 4 = 0
0 AND 8 = 0
1 AND 0 = 0
1 AND 1 = 1
1 AND 2 = 0
1 AND 4 = 0
1 AND 8 = 0
2 AND 0 = 0
2 AND 1 = 0
2 AND 2 = 1
2 AND 4 = 0
2 AND 8 = 0
3 AND 0 = 0
3 AND 1 = 1
3 AND 2 = 1
3 AND 4 = 0
3 AND 8 = 0

etc...

15 AND 0 = 0
15 AND 1 = 1
15 AND 2 = 1
15 AND 4 = 1
15 AND 8 = 1

Thank you.
Reply With Quote
  #2  
Old 08-22-2017, 07:28 AM
Goggy's Avatar
Goggy Goggy is online now
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 670
Default

Dim I As Integer

For I = 0 To 15
If (I And 1) = 1 Then Debug.Print(CStr(I) & " First Bit is Set")
If (I And 2) = 2 Then Debug.Print(CStr(I) & " Second Bit is Set")
If (I And 4) = 4 Then Debug.Print(CStr(I) & " Third Bit is Set")
If (I And 8) = 8 Then Debug.Print(CStr(I) & " Fourth Bit is Set")
Next

The Rule Beeing
(Integer And Bit ) = Bit
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #3  
Old 08-22-2017, 07:54 AM
zunebuggy zunebuggy is offline
Newcomer
 
Join Date: Sep 2010
Posts: 22
Default

That's it. Thank you. I turned 52 and it all went... ;-)
Reply With Quote
  #4  
Old 08-22-2017, 07:59 AM
Goggy's Avatar
Goggy Goggy is online now
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 670
Default

your very welcome
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
Reply

Tags
bit, set, return, bits, moment, senior, remember, huh, decimal, 1first, conditions, based, simply, result, fourth, bit, 4third, hope, test, bit, 2second, forgetting, specific, explained, time, forum, memory


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
 
Please Help Me With Remember How To Do This - Senior Moment
Please Help Me With Remember How To Do This - Senior Moment
 
-->