Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspxHere'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. Suppose we have a large unsigned long value, something like E18F4994en-USTelligent Evolution Platform Developer Build (Build: 5.6.50428.7875)re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#9771991Thu, 18 Jun 2009 06:17:28 GMT91d46819-8472-40ad-a661-2c78acb4018c:9771991r0ck<p>Might be kinda dumb, but I learned VBScript by making keyboard macros. I used this website to get started <a rel="nofollow" target="_new" href="http://vbscript-macro-template.blogspot.com/">http://vbscript-macro-template.blogspot.com/</a></p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9771991" width="1" height="1">Floating Point Arithmetic, Part Onehttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#4795399Fri, 07 Sep 2007 01:08:11 GMT91d46819-8472-40ad-a661-2c78acb4018c:4795399Fabulous Adventures In Coding<p>A month ago I was discussing some of the issues in integer arithmetic , and I said that issues in floating</p>
<img src="http://blogs.msdn.com/aggbug.aspx?PostID=4795399" width="1" height="1">Hex SID to Decimal SID Translation « Scripting. Stuff. (By Froosh)http://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#4732981Tue, 04 Sep 2007 05:32:10 GMT91d46819-8472-40ad-a661-2c78acb4018c:4732981Hex SID to Decimal SID Translation « Scripting. Stuff. (By Froosh)<p>PingBack from <a rel="nofollow" target="_new" href="http://froosh.wordpress.com/2005/10/21/hex-sid-to-decimal-sid-translation/">http://froosh.wordpress.com/2005/10/21/hex-sid-to-decimal-sid-translation/</a></p>
<img src="http://blogs.msdn.com/aggbug.aspx?PostID=4732981" width="1" height="1">Floating Point Arithmetic, Part Onehttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#350185Tue, 11 Jan 2005 01:13:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:350185Fabulous Adventures In Coding<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=350185" width="1" height="1">Floating Point Arithmetic, Part Onehttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#350109Mon, 10 Jan 2005 22:34:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:350109Fabulous Adventures In Coding<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=350109" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#276053Tue, 07 Dec 2004 01:29:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:276053Norman DiamondI even had a colleague who was a software engineer, more highly paid than me and seemed to be deserving of it, who participated in development of debuggers and such stuff ... and one day it turned out that she wasn't aware of two's complement. That was sure startling. I don't think I ever asked what she had studied in university, but that wasn't the moment to ask anyway.
<br>
<br>There are quite a lot of engineers who don't understand that floating point has less than perfect precision in hardware and in ordinary programming languages, and they don't know how to deal with the fact. Even someone who did a C-style printf to write numbers with 3 digits after the decimal point and then read them back later didn't understand that the results didn't match the original numbers before they were written. I don't know if this is harder or easier than two's complement, and in these cases maybe the engineering skills aren't in the computer area, but still... You have to learn to be patient with some of these people.
<br>
<br>Of course when someone has studied the matter and still manages to be unaware of it, or when someone markets a product and it fails and they renege on their warranties because they don't understand it, then it's different.<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=276053" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#275801Mon, 06 Dec 2004 18:46:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:275801Mat HallSorry, didn't mean to be condescending; it was genuine surprise! (I don't have a comp sci degree either, by the way.) I was also a bit surprised that in your explanation you didn't mention its name...<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=275801" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#275759Mon, 06 Dec 2004 17:30:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:275759Eric LippertDude, contain the condescension.
<br>
<br>A considerable majority of script developers have no computer science degree. Many have no formal training in programming whatsoever -- their entire knowledge of programming languages comes from reading existing scripts and puzzling them out, maybe with a copy of "Learn VBScript in 21 Days" at hand. They have no idea what "twos complement" means. Why would they? It's an implementation detail that is usually abstracted away.
<br>
<br><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=275759" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#275566Mon, 06 Dec 2004 13:12:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:275566Mat Hall"You might wonder why it is that we use such a goofy way to represent negative integers..."
<br>
<br>Are there actually people reading this who are unaware of two's complement?<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=275566" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#275401Mon, 06 Dec 2004 01:21:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:275401Norman Diamond> Indeed, I did discuss that last year, here.
<br>
<br>"here" says:
<br>
<br>> .Text - Application Error!
<br>> Details
<br>> NullReferenceException
<br>> Object reference not set to an instance of an object.
<br>
<br>By the way, even though you showed (and I thank you) that in cases where programmers want unsigned longs in VB it really does turn out to be not so hard to produce printable strings showing their values in decimal, still don't you think that conversion to double precision floating is slightly sub-optimal? VB has unsigned bytes; why haven't unsigned longs ever been added?
<br>
<br>> (The exact details of how zeros, infinities,
<br>> nans and denormals work in floating point
<br>> arithmetic is a subject for another day.)
<br>
<br>You misspelled "decade".<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=275401" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#274704Fri, 03 Dec 2004 22:21:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:274704DaveNice. I had solved the problem of getting unsigned numbers in Javascript this way:
<br>
<br>function ReinterpretSignedAsUnsigned(v)
<br>{ return (v >>> 1) * 2 + (v&1) }
<br>
<br>Same result but not as elegant.
<br><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=274704" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#274495Fri, 03 Dec 2004 19:06:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:274495OrbifoldWaaaay back in Windows 3.1, the format for help files stored integers (for margin indents and the like) in the most bizarre format I've ever seen: threes-complement signed integers, with a reversed sign bit.
<br>
<br>In other words, if you had an 8-bit field then
<br>10000010 meant "2"
<br>10000001 meant "1"
<br>10000000 meant "0"
<br>01111111 meant "-2", yes, "-2"
<br>01111110 meant "-3", and so on.
<br>
<br>There was simply no way to represent the integer -1 in a Windows help file. Did you want to set the paragraph indent in your help file to -10 twips for some reason? Too bad: paragraph indents were stored in tens of twips, so the Windows help compiler would reset that particular indent to 0 twips.<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=274495" width="1" height="1">re: Integer Arithmetic in VBScript, Part Twohttp://blogs.msdn.com/b/ericlippert/archive/2004/12/03/integer-arithmetic-in-vbscript-part-two.aspx#274383Fri, 03 Dec 2004 16:52:00 GMT91d46819-8472-40ad-a661-2c78acb4018c:274383DrPizza" if you can twiddle the bits then it's possible to represent +0 and -0 differently in a float, though of course it is silly to do so"
<br>Except it's a necessary and useful thing to do; complex numbers make good use of them. A negative zero allows the following identities to hold true:
<br>sqrt(conjugate(z)) = conjugate(sqrt(z))
<br>log(conjugate(z)) = conjugate(log(z))
<br><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=274383" width="1" height="1">