Results 1 to 6 of 6

Thread: AND operator in VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Regular
    Joined
    Apr 2018
    Posts
    10
    Location
    Quote Originally Posted by Kris Kurek View Post
    I will appreciate it very much if somebody can instruct me how does AND operator work in the following code
    wyn1 shows 92 - where does it come from - I can't understand

    Thanks in advance

    Sub tst()
    Dim wyn As Long, wyn1 As Long

    wyn = 167772 / 256 ^ 0
    wyn1 = wyn And 255
    Debug.Print wyn1
    End Sub
    167772 in binary is 0010 1000 1111 0101 1100 (hex 00028f5c) . when that is logically "anded" with 255 (in binary 0000 0000 1111 1111) you should get 92 (0000 0000 0101 1100) or hex 5c.

    basically you are asking for the remainder of a number divided by 256.

    the AND compares each bit in one number with the corresponding bit in the other number. If both are "1" then the result is "1" otherwise the result is "0". 255 is 8 bits of "1"s.
    Last edited by daSpud; 09-19-2018 at 09:41 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •