Click here to Skip to main content
15,901,001 members
Home / Discussions / C#
   

C#

 
GeneralRe: OK, how would I do this in c# please Pin
stephen.darling16-Sep-10 14:31
stephen.darling16-Sep-10 14:31 
GeneralRe: OK, how would I do this in c# please Pin
Luc Pattyn16-Sep-10 14:51
sitebuilderLuc Pattyn16-Sep-10 14:51 
GeneralRe: OK, how would I do this in c# please Pin
AspDotNetDev16-Sep-10 15:46
protectorAspDotNetDev16-Sep-10 15:46 
AnswerRe: OK, how would I do this in c# please Pin
PIEBALDconsult16-Sep-10 16:15
mvePIEBALDconsult16-Sep-10 16:15 
GeneralRe: OK, how would I do this in c# please Pin
stephen.darling16-Sep-10 16:50
stephen.darling16-Sep-10 16:50 
AnswerRe: OK, how would I do this in c# please Pin
David Skelly16-Sep-10 22:22
David Skelly16-Sep-10 22:22 
GeneralRe: OK, how would I do this in c# please Pin
AspDotNetDev17-Sep-10 10:14
protectorAspDotNetDev17-Sep-10 10:14 
Questionjust cant get this code to produce correct value Pin
stephen.darling16-Sep-10 10:08
stephen.darling16-Sep-10 10:08 
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
AnswerRe: just cant get this code to produce correct value Pin
Luc Pattyn16-Sep-10 10:24
sitebuilderLuc Pattyn16-Sep-10 10:24 
GeneralRe: just cant get this code to produce correct value Pin
stephen.darling16-Sep-10 10:43
stephen.darling16-Sep-10 10:43 
GeneralRe: just cant get this code to produce correct value Pin
Luc Pattyn16-Sep-10 10:50
sitebuilderLuc Pattyn16-Sep-10 10:50 
AnswerRe: just cant get this code to produce correct value Pin
T M Gray16-Sep-10 10:40
T M Gray16-Sep-10 10:40 
GeneralRe: just cant get this code to produce correct value Pin
stephen.darling16-Sep-10 10:58
stephen.darling16-Sep-10 10:58 
GeneralRe: just cant get this code to produce correct value Pin
Richard MacCutchan16-Sep-10 22:44
mveRichard MacCutchan16-Sep-10 22:44 
GeneralRe: just cant get this code to produce correct value Pin
T M Gray17-Sep-10 4:08
T M Gray17-Sep-10 4:08 
GeneralRe: just cant get this code to produce correct value Pin
Richard MacCutchan17-Sep-10 6:04
mveRichard MacCutchan17-Sep-10 6:04 
GeneralRe: just cant get this code to produce correct value Pin
AspDotNetDev16-Sep-10 12:04
protectorAspDotNetDev16-Sep-10 12:04 
AnswerRe: just cant get this code to produce correct value Pin
AspDotNetDev16-Sep-10 12:47
protectorAspDotNetDev16-Sep-10 12:47 
QuestionDatetimepicker: manual input Pin
mSh198516-Sep-10 3:36
mSh198516-Sep-10 3:36 
AnswerRe: Datetimepicker: manual input Pin
Łukasz Nowakowski16-Sep-10 4:02
Łukasz Nowakowski16-Sep-10 4:02 
AnswerRe: Datetimepicker: manual input Pin
Mycroft Holmes16-Sep-10 16:04
professionalMycroft Holmes16-Sep-10 16:04 
GeneralRe: Datetimepicker: manual input Pin
mSh198516-Sep-10 20:17
mSh198516-Sep-10 20:17 
AnswerRe: Datetimepicker: manual input Pin
V.16-Sep-10 20:09
professionalV.16-Sep-10 20:09 
GeneralRe: Datetimepicker: manual input Pin
mSh198516-Sep-10 20:18
mSh198516-Sep-10 20:18 
Questionhow to convert a column in gridview to combobox after binding?? Pin
leeoze16-Sep-10 3:26
leeoze16-Sep-10 3:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.