|
den2k88 wrote: If such things can be conceived there is still hope for VB7 The official name for VB7 is "C#".
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
As the title states, recently I have seen very strange behavior using gethostbyname on Windows 10. We are implementing an interface using CIP to talk to a PLC. CIP is a protocol used to talk to industrial I/O devices and PLCs over Ethernet. It has it's own share of weirdness too and is what started all of this. We are talking to Allen Bradley PLCs and it's a real PITA. We configure these "assembly instances" in the PLC and one of their parameters is the IP address of the target computer. To implement the interface we are using a library we bought because the protocol is rather complex. It has this quirk whereby the IP address you configure for your computer will not work directly. To be more precise, it won't work if it is the primary IP address of a NIC. It has to be the secondary address which is configured using the "Advanced Options" of the control panel page for networking. Here is where the really strange part comes in. When I first configure the secondary address for a NIC it won't work. I have to add the address, accept all options, and close the dialogs, then re-open them, delete the address, and close them again. Then I have to re-open the option dialogs and re-enter that address and accept the changes. Only after doing all of that will it work correctly and I have seen this on four different machines. Where gethostbyname comes in is it is called to enumerate the addresses and find a match to the one you ask for. Unless the procedure I described is followed it will not see the secondary address so the interface initialization fails. You can open the dialogs and verify it is there but the function just will not see it unless it is deleted and then added back in.
I don't recall seeing such weirdness before but, of course, this is Windows 10. Yee haw.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Cache? A lot of IP address stuff is cached all over the place. Maybe your magic incantation is what it takes to kick something into a cache refresh.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
try "ipconfig /flushdns" after adding the secondary address
|
|
|
|
|
On Win NT 4.0, the NIC could support a huge number of IPs.
At least 16. The GUI could not handle that many so we would directly edit the registry to add additional IPs.
We may have had to reboot after, but it always worked and sounds easier than your procedure.
|
|
|
|
|
I was told that there's no way to undo an OR as it loses value in the output..
I fumbled upon a formula , to undo an OR
v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val )
100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 )
100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 )
255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )
|
|
|
|
|
Maybe you should be more clear about what you are saying.
|
|
|
|
|
If you already have both original values in order to "undo" the OR, you've already effectively undone the OR. Or am I missing something? Pretty sure this is an equivalency too, not an undo. If it was an undo it would generate two values from a single OR'd value, or generate a value given an OR'd value and one of the original values.
|
|
|
|
|
But, what's the utility of using this type of syntax to "exec-undo" "dual-values"?
|
|
|
|
|
To stay with binary logic operations, what your formula boils down to is (using C syntax) :
A | B = ( A ^ B ) | ( A & B ) That is not "undoing" the OR operation. That is a sequence of operations which arrive at the same result. To undo A | B = C you need to perform operations on C with B to give a result of A or operations on C with A that give B.
I find it easier to do binary logic with hexadecimal numbers so with the first numbers,
100 = 0x64
5 = 0x05
0x64 | 0x05 = 0x65 To undo the OR what you need is
0x65 ? 0x05 = 0x64 or
0x65 ? 0x64 = 0x05 I don't know what that expression would be and I can see why you were told it is impossible.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
albert_redditt wrote: I was told that there's no way to undo an OR as it loses value in the output..
That is correct.
Boolean algebra is implemented in programming languages but it still originates from that branch of mathematics.
If you have a value '1' there is no way you will ever be able to tell which of the following statements it originated from.
1 | 1
1 | 0
0 | 1
Because of that you cannot do that you cannot, in a programming language, recover the original values from a value that was created by oring other values together.
|
|
|
|
|
To reverse a OR operation, given on something like
A | B = C
solve for B knowing only A & C.
For example:
6 | B = 7
Given that, B could be 1 or 3 or 5 or 7. Any of those would work in the equation, and there is no way to know which it was.
Truth,
James
|
|
|
|
|
The formula is correct (though as mentioned it doesn't "undo" the OR, it computes the OR in terms of other operations) and I'll prove it algebraically, starting at the end and deriving that it must be equal to v1 | or_val .
( v1 ^ or_val ) + ( v1 & or_val )
= (the left and right operands do not "intersect", their bitwise AND is zero, in that case A + B == A | B)
( v1 ^ or_val ) | ( v1 & or_val )
= (OR distributes over AND)
(v1 ^ or_val | v1) & (v1 ^ or_val | or_val)
= (A ^ B | B == A | B)
(or_val | v1) & (v1 | or_val)
= (A AND A == A)
v1 | or_val
|
|
|
|
|
It uses the value you are trying to find to find the value you are trying to find. No point to it.
E.g. for X OR 9 = 11, use it to find the value of X.
|
|
|
|
|
I suspect the person telling you that meant there is no mathematical inverse to the OR operator - which means that the input of a function (or operator) must be reconstructable from the input to that function. In this sense, OR definitely has no inverse.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Rob Grainger wrote: the input of a function (or operator) must be reconstructable from the input to that function
That's trivial. It's reconstructing it from the output that's difficult.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
GitHub - samuelmarina/is-even[^]
Quote: This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;
They're up to 1,000,001 now. Help them grow!
TTFN - Kent
|
|
|
|
|
I could while away the hours
Conferrin' with the flowers,
Consulting with the rain;
And my head I'd be a scratchin'
While my thoughts are busy hatchin'
If I only had a brain.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|
|
Only works with base-10 ?
Surely it would be better written recursively.
modified 17-Aug-21 16:57pm.
|
|
|
|
|
I... what?! I thought you were joking for a second but there actually is a definition for even and odd in generic bases. In even bases it's the last-digit test - odd is odd, even is even; in odd bases it's a test of the sum of all digits - odd is odd, even is even. That makes complete sense; it's just not something I've ever considered
|
|
|
|
|
Ckuf me backwards with a shovel, it's the first time I hear this.
GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
PIEBALDconsult wrote: Only works with base-10 ?
You just need to add conversion functions and call them first.
function hexToDec(number) {
if (number === 1) return 1;
else if (number === 2) return 2;
else if (number === A) return 10;
else if (number === B) return 11;
}
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
You left out the glorious sister project:
It is also important to know if a number is odd, so additionally I created this other package @samuelmarina/is-odd
Spoiler: It's not just function isOdd(x) { return !isEven(x); }
|
|
|
|
|
function isOdd(x) { return isEven(x-1); } ?
function isOdd(x) { return isEven(~x); } ?
|
|
|
|
|
Your sanity only wishes those were the case
Also that second one is clever.
|
|
|
|