Results 1 to 5 of 5

Thread: [RESOLVED] VB's &HFFFF vs C#'s 0xFFFF

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Resolved [RESOLVED] VB's &HFFFF vs C#'s 0xFFFF

    In C#,

    int latch = 327710;
    int Result = latch & 0xFFFF;

    The computation gives 30.

    But why in VB6:

    Dim latch as Long
    Dim Result as long
    latch = 327710
    Result =(latch And &HFFFF)

    The Result gives 327710.

    Edited:
    Put & behind &HFFFF,Result =(latch And &HFFFF&), then the Result gives 30 as I expect.
    Lool like C# 0xFFFF is unsign Integer, so the equivalent in VB6 is &HFFFF&, right?
    Last edited by Jonney; Jul 18th, 2014 at 04:01 AM.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB's &HFFFF vs C#'s 0xFFFF

    No, an "int" in C# is a Long in VB, i.e. 32 bits.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: VB's &HFFFF vs C#'s 0xFFFF

    More to the point: (If I remember right) &HFFFF is an integer.... but &HFFFF& is a long ... it's all about keeping the same type across the entire expression.

    -tg

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB's &HFFFF vs C#'s 0xFFFF

    Yes, the &HFFFF, because it is an integer literal (= -1) is sign extended when converted to a long so becomes &HFFFFFFFF (-1).
    Putting the & on the end makes sure it is a Long literal, so is &H0000FFFF (= 65535), which is what you want.
    Last edited by passel; Jul 18th, 2014 at 11:05 AM.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: VB's &HFFFF vs C#'s 0xFFFF

    Quote Originally Posted by passel View Post
    Yes, the &HFFFF, because it is an integer literal (= -1) is sign extended when converted to a long so becomes &HFFFFFFFF (-1).
    Putting the & on the end makes sure it is a Long literal, so is &H0000FFFF (= 65535), which is what you want.
    Thanks.
    20+ years old VB6 still has secret I never knew.

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