On the internet the rules says for XOR it becomes one if one value is 0 and another is 1. I got that point so:
0 1 1 1 0
0 1 1 0 1
0 0 0 1 1
What I don't get is how come when I add
23
12
31
How did it come up with 31?
What I suspect is the following:
23 is actually 2 followed with 3
12 is actually 1 followed with 2
In binary:
2 3 -> 10 11
1 2 -> 01 10
XOR gives you:
11 01 -> 3 1
Edit:
As suggested in comments, it could also be that you used OR instead of XOR:
10111 // 23
01100 // 12
11111 // 31
Related
I'm trying to reverse engineer a game database and have come to a roadblock.
I can load all the tables/fields/records , however I'm stuck when it comes to converting the record values to hex or bits
the values (in game) are as follows: (15 bits) 192 - (10 bits) 20 - (5 bits) 19 - (5 bits) 2
In the db file , it shows 00 C0 - 00 0A - A6 - 00
This is strange , because only the first value (00 C0) is the same in Hex (192)
The other values are different , I'm guessing this is because they are not full bytes (10 and 5 bits respectively) so it must be using a bit array.
This guess is further proven when I change the final value from 2 , to 31. The last 2 values in the db are changed, and the hex string becomes 00 C0 - 00 0A - E6 - 07
So what's the best way to get these 4 integers in to a bit array in PowerShell so I can try to determine what's going on here ? If it is not obvious to any more experienced programmers what is at play here. If required I could also use C# however I'm less experienced.
Thanks
I am not sure what you want to achieve. 5bits words are literally odd.
It could be that there is no clear conversion here but something like a hash. Anyways, you could technically count from 0 to 2^35 - 1 and poke that in your game and lookup the result in your database.
Let me give you a few conversion methods:
To bit array:
$Bits =
[convert]::ToString(192, 2).PadLeft(15, '0') +
[convert]::ToString( 20, 2).PadLeft(10, '0') +
[convert]::ToString( 19, 2).PadLeft( 5, '0') +
[convert]::ToString( 2, 2).PadLeft( 5, '0')
$Bits
00000001100000000000101001001100010
And back:
if ($Bits -Match '(.{15})(.{10})(.{5})(.{5})') {
$Matches[1..4].Foreach{ [convert]::ToByte($_, 2) }
}
192
20
19
2
To Int64:
$Int64 = [convert]::ToInt64($Bits, 2)
$Int64
201347682
To bytes:
$Bytes = [BitConverter]::GetBytes($Int64)
[System.BitConverter]::ToString($Bytes)
62-52-00-0C-00-00-00-00
Note that the bytes list is reverse order:
[convert]::ToString(0x62, 2)
1100010
I have a question.
I have a file with training data set. It looks like:
1 6 4 12 5 5 3 4 1 67 3 2 1 2 1 0 0 1 0 0 1 0 0 1 1
2 48 2 60 1 3 2 2 1 22 3 1 1 1 1 0 0 1 0 0 1 0 0 1 2
4 24 2 34 3 5 3 2 3 31 3 1 2 2 1 0 0 1 0 0 1 0 0 1 1
4 9 4 21 1 3 3 4 3 48 3 3 1 2 1 1 0 1 0 0 1 0 0 1 1
I have a neural network with 24 neurons in input layer, 12 neurons in hidden layer and 2 neurons in output layer.
When I start to train a network - an error appears:
The number of input neurons in the ann (24) and data (6) don't match.
But why? How you see there are 24 input data! Can you tell me, why this error is appear? Thx!
I use VS 2015, C#, Win forms;
FANN expects training data to be stored in a very particular format, see here.
The first line in the file is a kind of header, consisting of three space-separated numbers: the number of training records, the number of input neurons and the number of output neurons. Subsequent lines alternate input data and output data, so that each pair of lines constitutes a complete training record.
You have not included the header line, but FANN does not know that - so it is assuming that you have one training record, six input neurons and four output neurons. As the number of input neurons in your ANN does not match what it assumes to be the number of input neurons in your training file it is throwing an error.
It would normally then struggle to read the rest of the file anyway as it is not in the expected format.
I am trying to write a regular expression where only values from 1 thru 99 are allowed.
Valid values:
1
01
2
02
3
03
...
19
20
21
...
98
99
Everything else must throw an error like:
00
0
-1
1.0
1.
100
I currently have this:
^[1-9]([0-9]+$)
This is not working. It only accepts values from 10 and above.
This should do:
^(0[1-9]|[1-9][0-9]?)$
^(0?[1-9]|[1-9][0-9])$
first part covers 1 to 9 and the 0x
second part is for everything between 10 and 99
/^(0?[1-9]|[1-9][0-9])$/gm
Demo here.
Try this Regex:
^([1-9]|[1-9][0-9]|0[1-9])$/mg
Demo here Regex101
It uses the | operator which is equivalent to OR.
So basically this Regex is saying:
Is the number between 1 and 9?
OR
Is the first number between 1 and 9, and the second number between 0
and 9?
OR
Does the number begin with a 0 and end with a number between 1 and 9?
The flags on the end /mg just make it check each line for the demo, you may want to change or remove these.
Edit: For whatever reason I didn't see Kuba's answer. His is actually cleaner, but works in roughly the same way as this one should you have wanted an explanation.
This shoud work : ^(([0-9][1-9])|([1-9][0-9])|[1-9])$
I need to convert a number between 1 and 6000000 to a letter combination like ABCDE.
Less letters is better. but i'm guessing i will need 4 or 5.
Can someone point me in the right direction as how to write an algorithm to convert numbers to letters and back? only A-Z. (caps).
You need to convert to base-26 numbering: 0 is A, 1 is B, 25 is Z, 26 is BA, etc.
The Hexavigesimal Wikipedia article has code for conversion to base 26.
There are 26 letters in the alphabet.
TYou have 26^4 < 6 000 000 and 26^5 > 6 000 000
Then you will need 5 letters, for most of your elements
Now you just need to express your number in base 26.
Their is only one way to write an X in 0 ... 6 000 000 as follow:
X = a4*26^4 + a3*26^3+ a2*26^2+ a1*26^1+a0
ai in {0,...25} then you just map ai with a letter from A to Z
The most naive thing to do would be to let A,B,...,Z represent the numbers 0,1,...,25 and the just convert your number to base 26 to get the alphabetic conversion.
For example, there is a C# implementation in this answer to this post.
Well if you want to convert from the decimal representation, then there are 10 digits [0-9] and if you want to have one character per decimal digit in the result, then you will need ten alpha characters. But if you convert from the binary representaion, just replace every 0 with an 'A' and every 1 with a 'B'...
everything depends on how you want to do it... The base you decide to use will determine how many letters you will need.
as an example, to do it from a binary representation,
take the number mod 2. If the result is 0 add an 'A' if its a 1, add a 'B'
Divide the number by 2 (or rightshift it one position.)
repeat until number is zero.
start with value of 57
1. 57 Mod 2 = 1 A
2. 57 / 2 = 28
3. 28 Mod 2 = 0 BA
4. 28 / 2 = 14
5. 14 mod 2 = 0 BBA
6. 14 / 2 = 7
7. 7 mod 2 = 1 ABBA --- A musical group !
8. 7 / 2 = 3
9. 3 mod 2 = 1 AABBA
10. 3/ 2 = 1
11. 1 mod 2 = 1 AAABBA
12. 1 / 2 = 0 --- -done
You should equate A = 0, B = 1 and so on upto Z = 25.
This would become a number system with the base (or radix) 26.
With this in mind, two digits can represent numbers ranging from 0 - 675 (ZZ = 675).
3 Digits would represent 26^3. i.e 0 - 17575.
With 5 digits you can represent from 0 - 11881375 (ZZZZZ).
You can take any standard algorithm that converts between decimal to its own radix to do that.
Conversion between Number bases can be referenced for help.
I understand that the single ampersand operator is normally used for a 'bitwise AND' operation. However, can anyone help explain the interesting results you get when you use it for comparison between two numbers?
For example;
(6 & 2) = 2
(10 & 5) = 0
(20 & 25) = 16
(123 & 20) = 16
I'm not seeing any logical link between these results and I can only find information on comparing booleans or single bits.
Compare the binary representations of each of those.
110 & 010 = 010
1010 & 0101 = 0000
10100 & 11001 = 10000
1111011 & 0010100 = 0010000
In each case, a digit is 1 in the result only when it is 1 on both the left AND right side of the input.
You need to convert your numbers to binary representation and then you will see the link between results like 6 & 2= 2 is actually 110 & 010 =010 etc
10 & 5 is 1010 & 0101 = 0000
The binary and operation is performed on the integers, represented in binary. For example
110 (6)
010 (2)
--------
010 (2)
The bitwise AND is does exactly that: it does an AND operation on the Bits.
So to anticipate the result you need to look at the bits, not the numbers.
AND gives you 1, only if there's 1 in both number in the same position:
6(110) & 2(010) = 2(010)
10(1010) & 5(0101) = 0(0000)
A bitwise OR will give you 1 if there's 1 in either numbers in the same position:
6(110) | 2(010) = 6(110)
10(1010) | 5(0101) = 15(1111)
6 = 0110
2 = 0010
6 & 2 = 0010
20 = 10100
25 = 11001
20 & 25 = 10000
(looks like you're calculation is wrong for this one)
Etc...
Internally, Integers are stored in binary format. I strongly suggest you read about that. Knowing about the bitwise representation of numbers is very important.
That being said, the bitwise comparison compares the bits of the parameters:
Decimal: 6 & 2 = 2
Binary: 0110 & 0010 = 0010
Bitwize AND matches the bits in binary notation one by one and the result is the bits that are comon between the two numbers.
To convert a number to binary you need to understand the binary system.
For example
6 = 110 binary
The 110 represents 1x4 + 1x2 + 0x1 = 6.
2 then is
0x4 + 1x2 + 0x1 = 2.
Bitwize and only retains the positions where both numbers have the position set, in this case the bit for 2 and the result is then 2.
Every extra bit is double the last so a 4 bit number uses the multipliers 8, 4, 2, 1 and can there fore represent all numbers from 0 to 15 (the sum of the multipliers.)