|
Well - no. What it will do is throw an OverflowException "Value was either too large or too small for an Int32." when you try to do the convert in the C# version, or "Arithmetic operation resulted in an overflow." when you add the two together in the VB...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Not to mention converting the string manually instead of using Convert.ToString(TestInteger, 2)[^].
Or concatenating up to 31 strings during the conversion.
Or extracting a single character as a string instead of a character.
Or using CInt when you know it will be either "0" or "1" .
Or even the fact that the whole method could be replaced with:
Return If(TestInteger And (2 ^ (Nr - 1)) = 0, 0, 1)
And as for the fact that the function was only ever called with a single value of Nr , so that all the calls could be replaced with:
If (someValue And 64) <> 0 Then
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Now I see the point of lessons on Assembler... One of the first tasks was to "convert a decimal number to a binary representation and output to the console". If you have to write something in ASM, you desperately look for a smallest an easiest solution possible. Everybody should have such lessons. It teaches how the computer arithmetic works better than a houndred of calculus lectures.
Greetings - Jacek
|
|
|
|
|
Hehe finally i made my way to The Weird and The Wonderful. Enjoy!
I am sitting here writing some vc++ code cloning some Dom nodes with MSXML and cloneNode(VARIANT_BOOL deep) and i noticed that the deep cloning isn't working. After some googling i found this gem
typedef short VARIANT_BOOL;
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
#define VARIANT_FALSE ((VARIANT_BOOL)0)
with this explanation "This was developed by the Visual Basic folks" Clickety
Microsoft... the only place where VARIANT_TRUE != true
Thank you Visual Basic Team.
|
|
|
|
|
Welcome to W & W
http://authenticcode.com
|
|
|
|
|
This isn't a Microsoft thing. BASIC is the issue. non-zero = TRUE.
But it's still idiotic, and yet another reason to avoid lecacy crap such as BASIC.
|
|
|
|
|
I think this is a legacy from the pre-BASIC days of writing everything in assembler or direct hex (or octal) code. The value of -1 for a byte of 8 bits was 1111 1111 which also means true (all bits set to 1). This seems to have percolated into VB. I agree that it doesn't seem logical these days but way back then there was no strong typing and bool didn't really exist.
I may not last forever but the mess I leave behind certainly will.
|
|
|
|
|
I suspect you maybe right. something *convenient* and to do with cpu condition flags.
|
|
|
|
|
|
Yes, that always used to catch me out with VBA.
The worst part was that a check box had three states - true, false and indeterminate.
Guess what the indeterminate state was? Yes it was 1!
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
modified 26-Jun-13 10:24am.
|
|
|
|
|
What means a check box to the indeterminate?! Does it randomly mark it or not ? Or maybe just check it in half
|
|
|
|
|
A checkbox could be checked, not checked or have a light grey fill - the light grey fill meant indeterminate.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I think it's the check box that is filled in with a square. Like when you have an installer and there's a tree of options, and the root option has a check box that checks or unchecks all of the sub-options, and it turns to a square if you only check at least one but not all sub-options.
|
|
|
|
|
Indeterminate shows if there are sub-checkboxes belonging to this one, some of them can be checked, some unchecked. So the parent checkbox can't be 'checked' or 'unchecked' but partially-checked.
|
|
|
|
|
I think, the MFC (with C++) had this too, but there the value for intermediate was 2, IIRC.
|
|
|
|
|
It really was just plain old GW-Basic, QBasic, Basic-Plus and other miscreants.
Backward compatibility can backfire on occasion
|
|
|
|
|
It has been noticed that some of the developers knowingly/unknowingly use many global variables. But in my view, naturally they should feel confused at sometime, still some of them dont reveal the fact may be.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
Well I'm confused by your two sentences. Does that help?
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
I mean: dont they get confused if they over use Global variables?
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
|
I too dont know. It would be great if I get some discussion on this to get more clear picture.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
This isn't the place for such discussions - look at the top of the page.
"This forum is purely for amusement and discussions on code snippets."
For a more serious discussion (ish) try the lounge. But I'd suggest that you phrase it a little differently:
"Do you get confused if there are too many global variables?" is a lot clearer.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Ok, thanks.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
Mohammed Hameed wrote: But in my view, naturally they should feel confused at sometime, still some of them dont reveal the fact may be.
I don't understand that sentences.
Mohammed Hameed wrote: It has been noticed that some of the developers knowingly/unknowingly use many global variables.
Well, in 99,9% of all my actual project have no global variable. I write OOP so there is no need, except when I like to have one to offend my collegues.
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
Thank you for discussing on this topic.
I mean to say: Most of the developers who over use global variables, at some point in time, while development get confused whether to use them or avoid. Some of them may never reveal to others about this confusion.
http://authenticcode.com
|
|
|
|