|
What do you mean?
Do you mean is this an assignment from school?
If that is what you meant, no, it is not.
I am aged 31. I am in full time education, reading a degree in biomedical science at a university in the UK, and c# programming is simply a hobby.
aspdotnetdev, Yes, I suppose you have a point. I have indeed bit off more than I can chew. What can I say, I am very impatient, and want to know to much to quick
Time to start from the beginning I suppose.
Thank you everyone.
Kind regards,
Steve
|
|
|
|
|
Assuming you are starting with a number (n in the example below) you can just do:
Convert.ToString(n, 16)
If you have a String rather than an number, convert it to an int first.
Seems a bit of an obvious answer, so maybe I've misunderstood your question.
|
|
|
|
|
This is like the fifth post on the same topic. What wasn't mentioned is that the number can be very large (larger than a long can hold).
|
|
|
|
|
Hi again everyone.
I figured out how to represent a string of digits as its byte encoding representation, by converting c++ code that does just this, but it is producing the wrong result and I dont know why...
Here is the working code from my app...
private void button1_Click(object sender, EventArgs e)
{
string serialNumber = ("123456789");
byte[] output = new byte[5];
int result = decodeSerial(serialNumber, output, 5);
}
static int decodeSerial(string serial, byte[] result, int ResLen)
{
int m;
int digit, aux;
Array.Clear(result, 0, ResLen);
for (int i = 0; i < serial.Length ; i ++)
{
digit = serial[i] - '0';
aux = digit;
m = 0;
do
{
aux += result[m] * 10;
result[m++] = (byte)(aux % 255);
aux >>= 8;
}
while (m < ResLen);
digit *= 2;
}
return 0;
}
}
Now, when I pass in the string "123456789" I should get the byte encoding of:
0x75, 0xBC, 0xD1, 0x05 (Workis on my calculator AND it worked in a c++ app with the ORIGINAL c++ code,
But in this app, it produces the following hex data...
45, 9A, 71, 07
I def want to use this function, as when it works, I will be passing in a string of digits 41 in length, and besides, the original c++ function worked many months before when I tried it, but now I am using c#.
I would also prefer not to use bignum or any other type of function.
Can anyone help out please?
Thank you
Steve
|
|
|
|
|
stephen.darling wrote: while (m < ResLen);
I wasn't going to look at all this in any detail, however that line struck me as a meaningless statement as it repeats nothing until the condition becomes false. You may want to drop the semi-colon, or have to change something else altogether.
|
|
|
|
|
Hi.
What do you mean by 'drop the semi colon'?
If I remove the semi colon, I get an error telling me semi colon is required.
Also, if You dont mind me asking, how does it do nothing, as I step through my code, something is definatly happening, and I do end up with a number of bytes, just not what I get from my calculator.
Thank you again, Luc Pattyn.
Steve
|
|
|
|
|
sorry, my mistake. I overlooked the "do" keyword.
|
|
|
|
|
Why are you multiplying digit by 2 at the end of the for loop only to throw away the value and re-assign the value of digit at the top of the for loop? Why does decodeSerial return in rather than void if the value is meaningless? Why are you subtracting a string? What is the purpose of the aux variable when it is never different from digit during processing?
There are so many things wrong with this code that I really think you need to give up on this algorithm and start from scratch with something simpler.
|
|
|
|
|
I dont know is the short answer
I am trying my best, I got that code to work in the c++ version.
All I want to do is encode a string of digits to a byte array encoding.
The string is "123456789"
If I enter 123456789 on my calculator and press the "hex" button, it gives:
459A717
And that is what I want my code to do
Steve
|
|
|
|
|
stephen.darling wrote: If I enter 123456789 on my calculator and press the "hex" button, it gives:
459A717
All you need to do is convert your string to an integer then format that integer as a hex value, the same as you would in C++. See here[^] for information on formatting your output.
It's time for a new signature.
|
|
|
|
|
That isn't what he is doing. That hex button on his calculator doesn't do what the hex button does in windows calculator. Or he is giving bad example data just to confuse people and prevent them from helping (123456789 is not 0x459A717). Also, he needs to handle numbers larger than an int64.
|
|
|
|
|
Yes I figured that out by looking at the other question. A pity he didn't describe the full problem in the first place.
It's time for a new signature.
|
|
|
|
|
T M Gray wrote: Why are you subtracting a string?
The code actually subtracts a char from another char. Give this a try:
MessageBox.Show(("5"[0] - '0' + 1).ToString());
Perhaps not as intuitive as int.Parse, but it might just be faster.
The rest of your criticisms are valid.
|
|
|
|
|
I don't feel like reviewing that algorithm. Below is some pseudo-code for a new algorithm. Basically, you get the value of each base-10 digit, convert it to binary, then sum all those values (so, 123 would be 100 + 20 + 3, which in binary would be 1100100 + 10100 + 11, which would equate to 1111011).
Create a multiplier array. Set it to a value of 1 (i.e., a single element with the value set to 1).
Create a result array. Set it to a value of 0 (i.e., a single element with the value set to 0).
Create a secondary array. It's value will be set later.
Loop from the last char to the first char.
Create a product array by multiplying the char value by the multiplier array (note: 5x = x + x + x + x + x).
Initialize product array to the size of the multiplier array plus 1 (set each element to a value of 0).
Loop from 1 to char value.
Assign the product array the result of binary adding the product array and the multiplier array.
Binary add the product array to the value array and assign it to the value array, adding a head byte if necessary.
Multiply the multiplier array by 10 (note: 10x = x+x+x+x+x+x+x+x+x+x) (optimization: 10x = 8x + 2x).
Copy the multiplier array to the secondary array.
Multiply secondary array by 2.
Prefix a head byte to the secondary array.
Shift all the bits in the secondary array to the left by 1 bit (discard the first bit).
Multiply multiplier array by 8.
Prefix a head byte to the multiplier array.
Shift all the bits in the multiplier array to the left by 3 bits (discard the first 3 bits).
Binary add the secondary array and the multiplier array and assign the result to the multiplier array.
If the first byte in the multiplier is 0, remove it (this isn't necessary, but will reduce memory used).
Repeat loop until first char is reached and processed.
Remove any bytes from the head of the value array that are 0 (they are meaningless, just as the zeroes on 00000123 are meaningless).
When I say "array", I mean an array of unsigned bytes. You can find instructions online for how to add two binary values (note: an unsigned byte is essentially 8 binary values). This is not an efficient way to perform the conversion, but it seems like an intuitive one.
|
|
|
|
|
I've been googling a while for this, but haven't found anything useful..
When a user wants to enter a date manually in a datetimepicker (dateformat short), instead of selecting a certain date, the cursor stays endlessly in the monthfield. The user has to type a "/" or press the cursor right to go to the dayfield and yearfield to type the date.
I was wondering if there is a simple way of changing this behavior so the user can enter the date without having to press the cursor right button, and just input the numbers. (thus typing "10102010" instead of "10/10/2010")
I can't use a masked textbox because i don't want to lose the calendarfuncionality.
Does anyone have any experience with this? or are there controls available with this functionality?
Thanks in advance.
|
|
|
|
|
Why don't you ask it on Windows Forms forum?
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
Not using the standard control.
You could detect the user clicking into the edit box and swap out to a masked textbox, format the data on exit, pass the formatted value back to the dtp.
You will however find there is an endless number of potential formats that you need to cater for and it will drive you absolutely nuts. Most of us have chewed on this over the years. I recommend you simply tell the user it cannot be done, unless that is you have lots of spare time and nothing to fill it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I was afraid of that
I guess i have to wait until my boss is back from his vacation to ask him if i can waste my time with it
Thank you for your reply!
|
|
|
|
|
Is it an option to to put a masked textbox and datetimepicker one over the other with a checkbox next to them?
The Checkbox would toggle the readonly (datetimepicker) or the enter value (masked textbox) on or off.
V.
|
|
|
|
|
I thought of it as one of the possibilities..
thank you for your reply!
|
|
|
|
|
I use linq to sql.
I have a table of employees belong to a company by forigen key as companyID on the employees table. (I have compamies table as my main table)
the linq does it by it's self and knows that the two are related and after binding the context to the datagridview I get the employees table + column of the company name.
my goal is to convert or some how get to the point where I have a coulmn of the employee name and a combobox coulmn of the company which will be bound the companyID. so when I change the company it will know to update the companyID when I submit_changes() on linq context.
tnx
|
|
|
|
|
DataPropertyName
I added a new combobox column during runtime and bound it to the companies table.
set the valuemember and displaymember, and defined DataPropertyName to the same column name as the one I need it to be bound to and vwalla...
any changes made to the combobox saves it automaticly to the database (need to add an event on cell changes the have the context submit_changes() function)
|
|
|
|
|
I have a datagridview with the following code:
private void DgvAfsprakenAgenda_CellClick(object sender, DataGridViewCellEventArgs e)
{
int TempPatientNummer = Convert.ToInt32(this.DgvAfsprakenAgenda.Rows[e.RowIndex].Cells["PatientNummer"].Value.ToString());
}
My problem is as follows:
e.RowIndex is not the correct rownumber, but the shown rownumber in the following conditions:
- the datagridview is sorted in the user interface (by clicking on a column name)
- the user scrolls down to a row not originally visible
It seems that under these circumstances e.RowIndex returns the visible row instead of the row in the datagridview.
Anybody an idea ?
Rob
|
|
|
|
|
Of course it does. What did you expect?
|
|
|
|
|
I expected the rownumber of the datagridview.
I conclude from your answer that it is expected behaviour, so I have to restate the question, how do I find the patientnumber of the shown row, as now I get another rows patientnumber.
Thanks for your initial answer.
Rob
|
|
|
|