Fabulous Adventures In Coding
Eric Lippert is a principal developer on the C# compiler team. Learn more about Eric.
Here's another recent question I've received on bit twiddling in VBScript:
You discussed the issues with interpreting error results that come back interpreted as signed longs last year.
Indeed, I did discuss that last year,
This makes constructing the conversion functions you want pretty easy:
Function ReinterpretSignedAsUnsigned(ByVal x) If x < 0 Then x = x + 2^32 ReinterpretSignedAsUnsigned = xEnd Function
Function UnsignedDecimalStringToHex(ByVal x) x = CDbl(x) If x > 2^31 - 1 Then x = x - 2^32 UnsignedDecimalStringToHex = Hex(x)End Function
print
You might wonder why it is that we use such a goofy way to represent negative integers as "if the high bit is set then interpret it as an unsigned integer but subtract 2^32". The
00000000000000000000000000000111 = &h00000007 = 710000000000000000000000000000111 = &h80000007 = -7
very simple and straightforward, right? However, that system has one minor problem, and
The minor problem is that in this system there are two zeros -- a "positive zero" and a "negative zero", which is darn weird. That's a pretty minor problem though -- a problem shared, in fact, by floating point numbers. A 64 bit float consists of a 52 bit unsigned integer, a sign bit, and
The major advantage of the "subtract off
Think about that in the context of implementing subtraction. You want to calculate 10 - 3:
10 - 3
Get it? If you represent negative integers this way then you don't have to build another circuit on your chip to handle subtraction. You just build a circuit that handles unsigned integer addition. Integer subtraction and unsigned integer addition are the same operation at
PingBack from http://froosh.wordpress.com/2005/10/21/hex-sid-to-decimal-sid-translation/
A month ago I was discussing some of the issues in integer arithmetic , and I said that issues in floating
Might be kinda dumb, but I learned VBScript by making keyboard macros. I used this website to get started http://vbscript-macro-template.blogspot.com/