|
This is one of those questions where the answer is 'I wouldn't have started from here'. The 10 and 16 base number systems never intersect, so to convert an 80 digit decimal number to hex you need to convert the whole number in one piece. That requires an extended precision integer class and while that is entirely possible it seems like overkill for this when you could just store the key in hex to start with.
That said, it is fairly straightforward if you're using .Net 4:
string decimalString = "123456789";
BigInteger key = BigInteger.Parse(decimalString);
string hexString = key.ToString("X");
If not, you will have to find a replacement for that class. (I have one, but I'm at work so I don't have access to it and I haven't written an article about it.)
|
|
|
|
|
Hi everyone, thank you for the comments.
However, it seems that this function was working after all, it is just that the endian order was different.
If I pass in a string of digits, and supposed to get, for example:
0xCB45ED56
I would be getting:
0x56ED45CB
Well, I can live whith that, as I simply reverse the byte arrar when I am done.
So my only problem now is to write a function that does the reverse....
Take the byte array that my function produces (any length) and produce a string of digits representing it in base-10?
Kind Regards,
Stephen
|
|
|
|
|
Pseudo code:
BigInteger bigInt= 0;
while(remaining.Length > 4){
bigInt <<= 32;
byte[] last4 = (last 4 bytes of remaining);
bigInt += BitConverter.ConvertToUint32(last4);
remaining = (all but last 4);
}
I'm sure that you would actually write the array part with indexers and not reallocating every time, but that's essentially what you are trying to do. If you want the string then just take bigInt.ToString at the end.
Again though I must ask, why not just store your key in hex format in the first place?
|
|
|
|
|
BobJanova wrote: Again though I must ask, why not just store your key in hex format in the first place?
Could you please explain this for me?
The reason I need to provide a string of digits is that the keygenerator (a seperate application) produces a string of digits, so that I can provide these to the user in a readable format ("000000-000000-000000-000000-000000-000000-000000-0000000-00")
After striping the 6th check-digit from each group, the 41 digit string is decoded into a 17 byte array (the function I provided).
I can then use the byte array to perform the other functions that I have, which work on byte arrays by default.
Then, this leaves me with the final problem. Using simular code that I have to reverse the function for my key gen.
It will build 17 bytes from different functions, and this time encode it into the string above.
Kind Regards,
Stephen
|
|
|
|
|
Your key generator could generate keys in the same form but with hex digits. Unless the obfuscation of the decimal-to-byte representation change is of value to you, in which case, carry on.
|
|
|
|
|
BobJanova wrote: Your key generator could generate keys in the same form but with hex digits.
I would be interested to know more here? Like I said before, I am still very new to both c# and hex etc, so if you had any code example to show me what you mean I will take a look.
If the code you posted before is what you mean, then the only reason I didnt try it was because I got my c++ copied code to work first.
Really, all I want to be able to do is convert the big string of digits to hex, and be able to convert the hex back to the long string of digits.
The reason I think I need to use bytes is simply because my other functions either take byte arrays as auguments, or return byte arrays.
Thank you again,
Kind Regards,
Stephen
|
|
|
|
|
hi
I'm not professional in oop with c#. I need a sample proffessional project. I want to learn with a project.
If you konw, please send it to me.
if you have a better idea ,please guide me.
regards.
|
|
|
|
|
There are many sample projects on this website. Just look around.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I highly recommend you buy a book for a broad subject such as this. I haven't read it but perhaps this[^]?
There are many online tutorials and videos that will guide you through from start to finish. Maybe try this one from Microsoft[^].
I'm assuming you are a beginner or you wouldn't be asking such a question. If so, you will likely find it very difficult to understand what's going on in a full blown professional project without learning the basic fundemental OOP principles (and other coding methodologies) first.
|
|
|
|
|
Here are some you could try: http://tinyurl.com/3pu3zoe[^].
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
|
hello
i'm having dll built on c#2
when i try to use it on c#4
it doesn't work
so how i convert dll make on c#2 to work on c#4
md_refay
|
|
|
|
|
Pretty much there is zero information in that question.
So what you want to do.
1. Explain exactly what you are doing.
2. Explain exactly what the failure is.
|
|
|
|
|
ok
i have navigator pane that i used to use it on vs 2005
it's dll
when i add it to vs 2010
it generate an error
he type or namespace name 'MT' could not be found (are you missing a using directive or an assembly reference?)
the application didn't see dll reference
when i look at object browser i didn't find dll
i try to remove and add it many times
but the same result
md_refay
|
|
|
|
|
In your project's Solution Explorer, right click on references choose Add Reference and select the Browse tab. Then browse to the dll and click OK.
|
|
|
|
|
Recompile it.
|
|
|
|
|
i recompile it but the same error
md_refay
|
|
|
|
|
He means recompile the DLL source code using VS2010 and the project setting to the version of the runtime you want.
Did you try Daveys suggestion.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm using interop to save Excel files to CSV:
private static void saveAsCSV(string FileName)
{
FileName = FileName.Replace(".xlsx", "");
string destination = csvPath + "\\" + Path.GetFileName(FileName) + ".csv";
if (File.Exists(destination))
{
File.Delete(destination);
}
Application xl = new Application();
try
{
Workbook workbook = xl.Workbooks.Open(FileName);
Worksheet ws = (Worksheet)workbook.Sheets[1];
ws.SaveAs(destination, XlFileFormat.xlCSV);
Marshal.ReleaseComObject(ws);
}
finally
{
xl.DisplayAlerts = false;
xl.Quit();
Marshal.ReleaseComObject(xl);
}
}
After this run the instance of Excel is still open. What's wrong hre?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
I prefer to use ADO.net with the OleDb provider to do that.
But maybe you need to Dispose the xl object?
|
|
|
|
|
You need to release workbook as well.
You may also hit the transient object creation issue with xl.Workbooks ... you may have to do
Application xl = new Application();
var workbooks = xl.Workbooks;
Workbook workbook = workbooks.Open(FileName);
try
{
Worksheet ws = (Worksheet)workbook.Sheets[1];
ws.SaveAs(destination, XlFileFormat.xlCSV);
Marshal.ReleaseComObject(ws);
}
finally
{
xl.DisplayAlerts = false;
xl.Quit();
Marshal.ReleaseComObject(workbook);
Marshal.ReleaseComObject(workbooks);
Marshal.ReleaseComObject(xl);
}
|
|
|
|
|
Hi,
At the below line, its taking lot of time.
Application xl = new Application();
How to reduce that time. Thanks in advance.
|
|
|
|
|
Hi All,
I will be honest with you - I have taken exactly 1 ASP.NET class (instructional class...not object class, haha), so I might be doing this all wrong. I am developing an online employment application for the company that I work for. In my ASP.NET class, they taught us to try and avoid having our .aspx pages speak directly to the database (which I had always done before), so I am trying my best to use that best practice, but this is my first time doing it like this, and there's still some issues I'm trying to work out. I started building this application like I used to build all my other applications...but I think I need help from some more seasoned professionals on how to streamline what I've done in the past to make it fit what I'm trying to do now.
The way I organize my data is like this:
* DatabaseMethods.cs - class I created that connects to the database and has a queryDatabase(String query){} method that I use for sending queries and retrieving results (it returns DataTable objects that I work with when I send SELECT queries.)
* DataMethods.cs - class I created that has DataTable objects inside it for each of the data tables I'm interested in. This class accepts an instance of DatabaseMethods as a parameter in its constructor. Then, I have methods in here for pulling information out of my database and into my DataTable objects when I need them. (i.e. loadNames(){} would load the Names table from the database into the DataTable object Names in my DataMethods object.) My applications are typically fairly small, but I still usually parameterize these load***() methods so that the select queries aren't pulling entire tables in...my DBA would kill me...and since I am the DBA...that would be a form of suicide.
* I place instances of the DatabaseMethods object and the DataMethods object in the code-behind on my Master page. That way, throughout the whole application, on all the various screens, if I need, say, my Names table, I can just go like this: Master.DataMethods.loadNames(); Master.Names.Rows[0]["firstName"]; If I needed the first name field in the first row of that database table, for example.
* What I've now added are objects for my data, and an ObjectMethods.cs class for loading up those objects. All the objects themselves contain are their default constructors, the data fields I'm interested in for them, and methods that load a particular object from the database based on its ID, and methods that save that particular object to the database, whether by updating an existing row or inserting a new one. I sort of correlate objects to database rows. I wasn't sure how else to do that.
So, now that you understand how my application structure is organized (or messed up, depending on how you look at it - and I am welcome to suggestions on how to improve this), here is where my problem with the ObjectDataSource is:
I have a user control called RelativeSupervisorsRecordView.ascx, which has fields for last name, first name, middle name, and relationship. This is where applicants will enter in any supervisors at our company who are related to them, and how. The user can click an add button to get as many or few of these user controls as they want, in case they have anywhere from zero to a zillion relatives that are supervisors at my company.
The Relationship part of this user control is the issue. The relationship is a database table with ids 1 through 8, and values like Parent, Cousin, Child, Granparent, etc.
My user control connects to my Master page and calls the loadRelationshipTypes() method inside of my ObjectMethods class. That method, in turn, calls loadRelationshipTypes() in my DataMethods.cs class, which populates my Relationships data table. Then, the ObjectMethods class takes that data, creates 8 relationship objects out of it, and returns the objects in an IList<relationshiptypes> to my user control. Then, in the Page_Load method, my user control binds that IList to the DropDownList inside itself. When I watch this happen in debug mode, stepping through the code, everything looks good. The data is coming from the database ok, the objects are being created okay, I'm not seeing any exceptions generated on the DataBind command after I set the datasource property of the dropdownlist control, and all looks well. Then, when the page displays, my drop down list has nothing in it. What gives?
If code would make it easier, let me know and I'll post it.
|
|
|
|
|
Say I create a unit test that looks something like this below (autogenerated by VS) to test:
[TestMethod()]
public void UniContexPipeDataTest()
{
IResponse response = null; // TODO: Initialize to an appropriate value
ISeries series = null; // TODO: Initialize to an appropriate value
DateTime asof = new DateTime(); // TODO: Initialize to an appropriate value
UniContext target = new UniContext(response, series, asof);
target.PipeData();
Assert.Inconclusive("TODO: Implement code to verify target");
}
I know I have to initialize response and series but they are big and have lots of other objects and Interfaces embedded within them that need to be instantiated for the UniContext contructor and PipeData() to work correctly.
Q. How do I get the interfaces ready so that the constructor and method PipeData() pass in this unit test?
Right now I can create these objects and interfaces to pass into the target but they will be empty. Both IResponse and ISeries have tons of embedded interfaces and other things like other objects and properties inside them that need to be created and instantiated with data.
Do I need to start with the embedded object first and then do a ordered test unit test type deal?
Do I need to learn about stubs, external dependencies and creating mocks objects?
Any help/advice on this will be appreciated.
--------------------------------------------------------------------------------
|
|
|
|
|
Hi,
I need to make a Lucene exact case insensitive keyword match query.
I tried BooleanQuery to combine TermQuery and WildcardQuery. but it's case sensitive ...
Sample :
Keyword : Business -> Got Results
Keyword : business -> No results
please guide me to achieve this. Thanks in advance.
|
|
|
|
|