vb6 - C# Byte Handling -
i'm experiencing bit of issue while trying convert vb6 logic c#. in 1 of vb6 functions, has following statement:
w = not cbyte(w)
where w long
.
in example, after line evaluates in vb6, can see following change: before: w = 110
after: w = 145
however, in c#, i've rewritten method contain following code:
w = ~(byte)w;
but, when run same example, these results, instead: before: w = 110
after: w = -111
i same result doing:
w = ~(convert.tobyte(w));
i able correct results following change:
w = ~(byte)w & 0xff;
from can tell, looks c# converting sbyte
though it's not specified so. question is: there flaw in logic? way vb6 equivalent?
w
long
, let's it's int
, doesn't matter except it's easier explain.
w = ~(byte)w;
ok, w
cast byte
.. , int
because that's arithmetic operations do.
you solve taking justin's suggestion comments (which cast @ right moment: (byte)~w
), or this:
w ^= 0xff;
that not strictly same thing though, it's different if w
starts out value outside of range of byte
.
Comments
Post a Comment