Results 1 to 8 of 8

Thread: bitwise Not in vb.net?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    bitwise Not in vb.net?

    It's "~" in C#. I belive there isn't an operator for it in vb.net. But could someone at least explain how it works so I can somehow get it to work in vb.net?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB.NET Example . There are more if you just searched Google !

  4. #4

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    I had seen two of those links.... anyways, I thought there is a difference between the ~ and ! in C# (well there is, but basically they do the same thing, and that's all I wanted to know).
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Originally posted by MrPolite
    I had seen two of those links.... anyways, I thought there is a difference between the ~ and ! in C# (well there is, but basically they do the same thing, and that's all I wanted to know).
    No, they really don't!

    E.g.

    if(3 && !3)
    is never true.

    if(3 && ~3)
    is always true.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by CornedBee
    No, they really don't!

    E.g.

    if(3 && !3)
    is never true.

    if(3 && ~3)
    is always true.
    ok I'm confused would you care to explain?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    ! operates on boolean values.
    if(3 && !3)
    does this:

    First, it converts 3 to bool. 3 != 0, so it gets converted to true. Next it evaluates !3. Because ! (logical NOT) operates on bool, 3 gets converted to true again. Then it is negated to false and the AND expression fails.

    if(3 && ~3)
    does this:

    First it again converts 3 to true. The second part is different. ~ (bitwise NOT) operates not on booleans but on integers. 3 stays 3 and assuming 32-bit signed integers, the bit pattern 00000000000000000000000000000011 (3) is negated to 11111111111111111111111111111100 (-4).
    -4 then gets converted to bool and results in true (-4 != 0). So the AND expression succeeds.


    So bitwise NOT and logical NOT are logical NOT the same
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by CornedBee
    11111111111111111111111111111100 (-4).
    -4 then gets converted to bool and results in true (-4 != 0). So the AND expression succeeds.
    Umm, I'm not quite sure how that equates to -4! I assume the first bit designates the sign (+/-), but then wouldn't -4 = 10000000000000000000000000000100?



    EDIT:

    Never mind! I figured it out!

Posting Permissions

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



Click Here to Expand Forum to Full Width