[RESOLVED] Syntax Clarification Again
Good day. I'm not a C programmer but am trying to convert some code from C to VB and would appreciate clarification on a few C-related lines of code.
Example 1) value += ((-1) << x ) + 1;
value & x are both type int. I don't know how C shifts negative values but if someone can give me the result to the equation, I can figure out the rest on my own. Assume value is 3 and x is 8.
Example 2) if (!((x1 = blk[8*4] << 8) ...);
blk is an array. This line of code is first assigning x1 to blk[8*4] shifted left or is x1 assigned to blk[8*4] without the shift applied?
Example 3) x1 = x2 = x3 = x1 << 3
End result will be x1,x2,x3 will all have same value which is x1 shifted left, correct?
There are several hundred lines of code I'm trying to convert, and have encountered only a few situations where I'm doubting my interpretation. Thanks in advance.
Re: [RESOLVED] Syntax Clarification
For 'example 1', you don't have to change it as much as you did - you just have to remove the semi-colon (that's why I said it was nearly identical):
Code:
value += ((-1) << x) + 1
This works in VB and the result is -252.
Re: [RESOLVED] Syntax Clarification
I'm pretty sure LaVolpe is referring to VB classic which does not have any shift or compound assignment operators.
Because VB classics raise operator '^' is so horribly slow it makes a lot of sense to employ a small LUT to store the powers of two (BitLUT(0) = 1 ... BitLUT(10) = 1024 etc)
Code:
value = value + (-1 * BitLUT(x)) + 1
simplifies to
Code:
value = value - BitLUT(x) + 1
overflow checking turned off of course.