Predict The Output III

How many did you get right?

  • Zero

    Votes: 6 37.5%
  • 1

    Votes: 2 12.5%
  • 2

    Votes: 6 37.5%
  • 3

    Votes: 2 12.5%

  • Total voters
    16

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Ahh yes... it is coming back to me now! I remember doing those truth tables during my year attempting a computer-science degree many a year ago, ultimately ended up with a management degree! Explains why I spend a lot of time here on the board learning this programming stuff over and over again!

Thanks for the exceptional answer - you have a teachers style for sure.

Owen
 
Wow, clever stuff! :eeek:

For sure Colin, you explain things better than anyone!
 
Great explanation. I am left with one question - why is this even possible in VBA? Under what circumstances would someone want to do this?

EDIT - two questions - still don't get Rory's second joke...
 
It was about two's complement. I did say it wasn't funny...;)
It's actually very useful in VBA and is why you can just add things like MsgBox constants together - e.g.:
Code:
msgbox("Bit masked buttons", vbCritical + vbYesNo + vbSystemModal)
You are effectively using an Or bitmask.
 
I just skimmed that Wiki article. My brain now hurts, and I still don't get the msgbox constants thing. (You're right about the joke not being funny though ;) )
 
Hi Emma

I take your point. Understanding how they work is one thing but practical application is another, so let me give the example which was given to me when I first read about all of this.

Suppose you want to determine if an integer is odd or even. We can use AND to create a lightning quick function to do this:

Rich (BB code):
Sub test()
 
    Debug.Print IsOdd(0)
    Debug.Print IsOdd(1)
    Debug.Print IsOdd(2)
    Debug.Print IsOdd(-3)
    Debug.Print IsOdd(-10)
    Debug.Print IsOdd(32765)
    Debug.Print IsOdd(-32768)
 
End Sub
 
Function IsOdd(ByVal intValue As Integer) As Boolean
 
    If (intValue And 1) = 1 Then IsOdd = True
 
End Function


How does this function work?

If you look at the integer table in my previous post you can see that the one bit (on the right) is always on (1) when the number is odd.

The AND performs this operation:

Rich (BB code):
Decimal     Binary (Integer)
intValue    xxxx xxxx xxxx xxxx
AND
1           0000 0000 0000 0001
=
            0000 0000 0000 000?


There are only two possible outputs from this operation, depending on whether the x was on or off.

Rich (BB code):
Decimal     Binary (Integer)
0           0000 0000 0000 0000
1           0000 0000 0000 0001

The answer will only be 1 if the number passed into the function was odd.


Obviously this is just the proverbial tip of the iceberg.
 
Colin - that's pretty cool! Thanks!

Rory - thanks for that article. Don't understand it yet, but do at least have some idea what I don't understand...
 
Yah not 2 had me messed up. I knew it would be negative and implicitly an integer, but I forgot that when the sign bit is flipped you count backwards. Good One:)
 

Forum statistics

Threads
1,222,646
Messages
6,167,311
Members
452,109
Latest member
nathanle89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top