-
Jul 18th, 2014, 03:04 AM
#1
Thread Starter
Frenzied Member
[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.
-
Jul 18th, 2014, 09:04 AM
#2
Re: VB's &HFFFF vs C#'s 0xFFFF
No, an "int" in C# is a Long in VB, i.e. 32 bits.
-
Jul 18th, 2014, 09:53 AM
#3
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
-
Jul 18th, 2014, 11:02 AM
#4
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.
-
Jul 18th, 2014, 07:02 PM
#5
Thread Starter
Frenzied Member
Re: VB's &HFFFF vs C#'s 0xFFFF
Originally Posted by passel
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|