Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm reading some documentation (under NDA) where is says to do the following operation:
Rnd1[11..7] <+> Rnd2[11..7]
Rnd1 and Rnd2 represent an array of bytes.
What should operator <+> do here?
I've browsed through entire documentation and can't find an explanation.
It is likely an attempt to make an ASCII representation of the symbol ⊕, that symbol represents XOR.
So the documentation is likely telling you to take bytes 11 through 7 of Rnd1 and xor them with the same bytes in Rnd2
public byte[] YourOperator(byte[] rnd1, byte[] rnd2)
{
byte[] result = new byte[5];
for(int i = 7; i <= 11; i++)
{
result[i - 7] = rnd1[i] ^ rnd2[i];
}
return result;
}
Be careful to check if the 7..11 is a inclusive or exclusive upper bound, that will change the number of bytes you are working with from a 5 to a 4 and the <= to a <.
The fact you signed a NDA to get the documentation means you should have working relationship with the company that gave it to you, the best option is to contact them and ask for clarification so you know for sure what they meant.
I like the Linq way of doing things, e.g.
rnd1.Zip(rnd2, (r1, r2) => r1 ^ r2).Skip(7).Take(4);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Why does Rider DPA say that this code allocates int arrays?
foreach doesn't itself allocate anything (except space for some locals, which aren't heap allocations in this case). It is roughly equivalent to:
int result = 0;
using (IEnumerator<int> iter = numbers.GetEnumerator()) {
while (iter.MoveNext()) {
var number = iter.Current;
result |= 1 << (number - #base);
}
}
return result;
As you can see: it has literally no direct allocations, but whatever you pass in as numbers has 4 opportunities to do anything it chooses: GetEnumerator(), MoveNext(), Current, and Dispose(). We can't tell you what the input numbers is, but there's a good chance that the tool is measuring these invisible allocations and attributing them to the foreach.
Look at whatever numbers is.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
How generate all binary combination from 00000 -> 11111 using C# with the easiest way, Thank you.
An easy google search would probably gotten you the answer, but if you just want the binary representation of numbers from 0 to 32.
public static void Main()
{
for (int i = 0; i < 32; i++)
Console.WriteLine(Convert.ToString(i, 2).PadLeft(5, '0'));
}
for (int i= 0; i < 32; i++)
{
// i is a packed combination
// j-th bit is (i >> j) & 1
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Currently very new to C# and coding , so i will be more than happy if someone will explain me how to display how many digits the number has. For example the number 12345 has 5 digits.the main theme in the class is while loops so the answer probably need to contain while loop.TY
You can either use this
Math.Abs(myint).ToString().Length
and if you absolutely must use a while loop then
number = Math.Abs(number);
int length = 1;
while ((number /= 10) >= 1)
length++;
To test code
string.Trim().Replace("-","").Length
so if you have a number you should make it a string first using ToString()
The Length returns the number of characters that you hold within your string minus your white spaces (Because of the Trim()),i don't see why you would want to use the while loop in the first place.
Edit : if you have a minus number the .Replace() will take care of that.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm unable to determine why I don't get my expected output, given this code:
int periods = (location.Length / 2) - 1;
for (int index = 2, i = 0; i < periods; index += 3, ++i )
{
location = location.Insert(index, ".");
}
And a location of "C5032AC", I expect that location will equal "C.50.32.A.C" after my loop terminates; it is instead "C5.03.2AC". Can anyone explain what I'm missing here?
I would investigate using regular expressions to help you achieve this goal. You should be able to create a regular expression that matches specific patterns in the string, and you should be able to insert characters between those matches. Please see this article Regular Expressions MSDN
I've been asked to provide a bit of code to help support this. I don't believe regular expressions are overkill, and I believe something along the lines of this example will provide at least a step in the right direction.
line=Regex.Replace(line,#"([\w])(\d{2})(\d{2})(\w)(\w)","$1.$2.$3.$4.$5");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I need to scramble chars in word. And this scrambling must not be random. In other words, each time of scrambling (on the same word) the new result must be equal to last scramble result (on the same word). Very simple example is XOR. But XOR is very easy to decode and I need something more strength. Could you recommend library for such purpose that identically works on C# and Javascript?
Thank you for any advice!:)
You can use random with fixed seed if you really want to scramble characters:
string input = "hello";
char[] chars = input.ToArray();
Random r = new Random(2011); // Random has a fixed seed, so it will always return same numbers (within same input)
for (int i = 0 ; i < chars.Length ; i++)
{
int randomIndex = r.Next(0, chars.Length);
char temp = chars[randomIndex];
chars[randomIndex] = chars[i];
chars[i] = temp;
}
return new string(chars);
Although I don't really agree about what you were trying to do, here's a link to MD5 javascript library (assuming what you're trying to do is some kind of encryption). As for the C# part, it's a built in feature.
You can use any of the built in .NET classes to generate random numbers and use these to scramble your string. For all the subsequent scramble attempts you can use the result from the first scramble operation. This assumes that the result from the first call is stored somewhere.