Click here to Skip to main content
14,733,548 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I am writing an application where I need to return 16 digits to the user as product code.One of my objects returns a byte array of length 128. I need to convert these 128 bytes in to 16 digits.I am trying to achieve this as follows:-

Dim reg As New regProcess<br />
        Dim ProductCode As Byte()<br />
        Dim i As Integer = 0<br />
        Dim j As Integer = 0<br />
        Dim num As UInt64 = 0<br />
<br />
        ProductCode = reg.Register<br />
        If ProductCode.Length > 0 Then<br />
            txt_ProductCode.Text = ""<br />
            <br />
            While i < (ProductCode.Length / 8)<br />
                Dim var As UInt64 = 0<br />
                For j = 0 To 7<br />
                    var += Convert.ToUInt64(ProductCode(i))<br />
<br />
                    i += 1<br />
                Next<br />
                 txt_ProductCode.Text += Convert.ToString(var)<br />
               <br />
            End While<br />
        End If<br />
 End Sub

This doesn't guarantee to return 16 digits as I am taking the sum of 8 consecutive bytes.

My question is can anybody tell me how do I interpret those 128 bytes as 32 bit integers, so that I can display 16 digits as product code.
Any help is appreciated.


1 solution

You can't.
128 bytes will not fit into 16 digits. it will fit into 256 hexadecimal digits, but the only way to fit 128 bytes into 16 "digits" would be to use base 64 for your output values, which would be an "interesting" number base to use.

Do you really mean 128 bits or are you horribly confused here?
Mrudula Joshi 18-Jun-13 7:38am
I actually mean 128 bytes not bits.Currently I have settled on getting 16-20 digits but it fluctuates between 16-20 digits.Its like 90% of the time it returns 20 digits but in 10% cases I get 16-19 digits.Works, but not cool.
I do this

txt_ProductCode.Text = BitConverter.ToUInt16(ProductCode, i)

in the while loop now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900