|
No, it doesn't really make sense...
What is a "32 byte long string"? A string consists of characters, not bytes. It looks like you have a string containing 32 characters, but that will occupy 64 bytes.
Have you really stored the string in a byte[32] array? How? Have you encoded the string? Then you should decode the string using the same encoding.
Once you have the data as a string, you can split it up into 16 separate strings using the Substring method. Then use the Int32.Parse method with NumberStyles.AllowHexSpecifier to parse each two character string into a byte value.
---
Year happy = new Year(2007);
|
|
|
|
|
Yup, you're right - it's a 32 character long string, however it does only occupy 32 bytes - it's not unicode. No encoding required - it's pure ASCII and is stored as such.
Anyway after much head scratching, I've got the following code to work:
// sHash[32] is a byte array length 32
// eg: the hex value 'A6' is split into sHash[0] & sHash[1]
// the following code will amalgamate this character data into a
// byte array length 16
int l = 0, iFirst, iSecond;
for (int k = 0; k < 32; k += 2)
{
if (sHash[k] > '9')
iFirst = (sHash[k] - 'A') + 10;
else
iFirst = (sHash[k] - '0');
if (sHash[k+1] > '9')
iSecond = (sHash[k+1] - 'A') + 10;
else
iSecond = (sHash[k+1] - '0');
EnHash[l++] = Convert.ToByte(((iFirst * 16) + iSecond));
}
Thanks for your comments above - it's an interesting idea to use int32.parse - I'll give that a go just to see how that works - ultimately it's not too diferent from what I worked out.
Kind regards,
John.
|
|
|
|
|
You did it the hard way, you could use System.Globalization.NumberStyles
example:
int i=int.Parse("12",NumberStyles.AllowHexSpecifier);
sets i to 18 (or 0x12).
So you simply could pass a two-char substring to byte.Parse and reduce your
for-loop body to a single statement.
Luc Pattyn
|
|
|
|
|
That's very cool Luc, thank you.
I think I'll implement that as I guess it will make the program run much faster!
Kind regards,
John.
|
|
|
|
|
Okay, having implemented your code I've got a saving of three seconds with 2755 hashes processed.
My code took 2 mins 33 secs to process, whereas yours took 2 minutes 30 - that's 18.3 hash conversions per second! This is a small sample file so I'm sure that in the real world application of this the savings will be very significant.
Many thanks for your help.
Kind regards,
John.
|
|
|
|
|
|
code_wiz wrote: Is there any reason why MS did not support databinding in these controls even in .NET 2.0?
I think I miss your point!! Both TreeView and ListView have a DataBindings property inherited from Control class, available both in the designer and the code.
Regards
|
|
|
|
|
Hi all
I'm new to C# multithreading and I read that to resolve deadlock it is best to use monitor with timeout.With this in mind I used the following code to see what happens to the deadlocking generated.
The result is the following exception
Unhandled Exception: System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code.
Why this? What's wrong with my code or my approach?
Regards
manuStone
class ThreadFoos
{
public static void First()
{
Monitor.TryEnter(ResourceA, 1000);
try{
Thread.Sleep(500);
Monitor.TryEnter(ResourceB, 1000);
try{
Console.WriteLine("First");
}
finally{
Monitor.Exit(ResourceB);
}
}
finally{
Monitor.Exit(ResourceA);
}
}
public static void Second()
{
Monitor.TryEnter(ResourceB, 1000);
try{
Thread.Sleep(500);
Monitor.TryEnter(ResourceA, 1000);
try{
Console.WriteLine("Second");
}
finally{
Monitor.Exit(ResourceA);
}
}
finally{
Monitor.Exit(ResourceB);
}
}
private static object ResourceA = new Object();
private static object ResourceB = new Object();
}
|
|
|
|
|
hi there.
this is what i think.
to start with
http://msdn2.microsoft.com/en-us/library/system.threading.monitor.exit.aspx[^]
which implies that Monitor.Exit can be called on a thread , for a resource only if that thread has already acquired lock for that resource.
you are calling Monitor.Exit (one out of try statements) on threads without assuring that a thread has already successfully acquired monitor on a specified resource. (i.e Monitor.TryEnter may not have been successfull). please Check the returned value from Monitor.TryEnter for both 'First' and 'Second' rountines.
regards.
|
|
|
|
|
Thank you very much for your resposne.
Have a nice day.
Regards
manuStone
|
|
|
|
|
I looked into the DDK which I guess is now know as the WDK. However, its a 1gig download which I would much rather not do. Is there an alternative way to do this in C#?
I would like to build some cmds and then send them to my drive, and get the responses back. How does one do this in the C# environment?
Thx.
|
|
|
|
|
Can you explain what you want to do?
|
|
|
|
|
I would like to implement the article that used the DDK listed here: http://www.codeproject.com/system/mydvdregion.asp
Except in C#. The WDK is for C and C++ and is a 1-2 gig download I would much rather not do. Any other libraries for sending CDBs to a drive? Thx.
Any help?
|
|
|
|
|
Why do you need the DDK? If you look through the source code you'll see that nothing in the DDK is referenced, he's simply borrowed definitions from the DDK so that people don't need to download it.
To use this in C# all you need to do is translate the C++ to C# et voila. It uses nothing special you'd just need to use P/Invoke to send the commands using DeviceIOCtrl.
I have no idea what I just said. But my intentions were sincere.
|
|
|
|
|
Cheers to you. I'm now on the right track. Basically I load in the kernall32.dll and I can call the DeviceIoControl() method from there. P/Invoke is a way to make interop possible by loading .dlls from the past. Very nice. Thanks very much Ed.Poore
Many Thanks.
Try
|
|
|
|
|
Hi to all!
I would like to ask you which coding convention do you use?
Regards,
|
|
|
|
|
That's a very broad question, how do you mean ?
I use braces like this
try
{
}
not
try{
}
I use _ and camel case for private variables, and I capitalise the first letter of public and protected methods/variables.
I make sure all variables are private
I don't use Hungarian notation
What else were you hoping for ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
oops. i refreshed the page before responding to this..
|
|
|
|
|
Hi every one,
I have server/client programming.
I'm using Remoting idea. I have server that should send the device(web cam) to the client so he can use it to capture video. But I have failed to send the device???
Can any one tell me how to send the device using the remoting? is it creating new Filter or what??
If there is any other simple & better idea other than remoting please tell me.
Thank u any way
Ali
|
|
|
|
|
Why would you want to do that? Wouldn't it be better to set-up a streaming server or something like that, take a look at Windows Media Encoder[^]. Just set-up your server and connect to it from the client program.
|
|
|
|
|
Um can you explain more clearly for those who missed the earlier question?
|
|
|
|
|
I'm writing a program that needs to take a list of hostnames/usernames/passwords and change each machine's registry settings over the network. I've tried using OpenRemoteBaseKey, but that only allows for a hostname input. I have limited network programming experience and was wondering if there was an easy way I could connect to each of my nodes over the network to change the registries. I can elaborate if needed. Thanks in advance!
-Ryan
|
|
|
|
|
|
Sorry if it sounds like a stupid question. I did a bunch of searching before I asked here, but I'm kind of lost as to what's a good way to do this. Most links just explained how to access remote registries that you already have permission to access. If you could just point me in the right direction, I'd really appreciate it.
|
|
|
|