473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Byte to Chr - not correctly translated!!

I have a String outputhex which consists of unicodetext translated into hex.
example: test = 7400650073007400

now i translate each two characters of the hexstring (outputhex) into byte
and then into chars. but this is the point where something is wrong...
(having the byteorder mark removed would also be very good)

"Schließen" gets to "Schlie鿃攀渀" and so on...

Here is the code:

Dim intIndex As Short
Dim j As Integer
Dim ch As Char

Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)

For intIndex = 1 To Len(outputhex) Step 2
j = CByte("&H" & Mid(outputhex, intIndex, 2))
ch = Convert.ToChar(j)
file.Write(ch)
Next

file.Close()


Thanks for the help, its urgent
May 16 '06 #1
18 1576
"kenny" <ke***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
I have a String outputhex which consists of unicodetext translated into
hex.
example: test = 7400650073007400

now i translate each two characters of the hexstring (outputhex) into byte
and then into chars. but this is the point where something is wrong...
(having the byteorder mark removed would also be very good)

"Schließen" gets to "Schlie???" and so on...


Correct me if I'm wrong, but aren't characters in VB.NET
two bytes in length rather than one?

--
Charles Appel
http://charlesappel.home.mindspring.com/
Home of Chuck's Poker Libraries for Delphi,
Chuck's Video Poker and Chuck's Toys
May 16 '06 #2
yes they are unicode... you need to translate the text format to accept
standard ASCII

"Charles Appel" <ch**********@mindspring.com> wrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
"kenny" <ke***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
I have a String outputhex which consists of unicodetext translated into
hex.
example: test = 7400650073007400

now i translate each two characters of the hexstring (outputhex) into
byte
and then into chars. but this is the point where something is wrong...
(having the byteorder mark removed would also be very good)

"Schließen" gets to "Schlie???" and so on...


Correct me if I'm wrong, but aren't characters in VB.NET
two bytes in length rather than one?

--
Charles Appel
http://charlesappel.home.mindspring.com/
Home of Chuck's Poker Libraries for Delphi,
Chuck's Video Poker and Chuck's Toys

May 17 '06 #3
Brian,
yes they are unicode... you need to translate the text format to accept
standard ASCII


I assume you mean a kind of Extended ASCII
standard ASCII is 7 bits where the ß (German character) is probably in the
kenny's code set.

Cor
May 17 '06 #4
> Here is the code:
For intIndex = 1 To Len(outputhex) Step 2
j = CByte("&H" & Mid(outputhex, intIndex, 2))
ch = Convert.ToChar(j)
file.Write(ch)
Next

Hi,
I have a related problem:
getting an MD5 string.

There are a few md5 databases e.g. http://md5.rednoize.com which return
the md5 hashes of your input strings. Can this be done by some type
conversion?
I tried the following but cannot get the type converstion right:

Public Function MD5String(vData As String) As String
Dim DBytes(vData.Length) As Byte, i As Integer
For i = 0 To vData.Length - 1
DBytes(i) = Convert.ToByte(Convert.ToChar(vData.Substring(i, 1)))
Next
Dim md5 As New MD5CryptoServiceProvider()
Dim HBytes As Byte() = md5.computeHash(DBytes)
Dim retstr As String
retstr = ""
For i = 0 To HBytes.Length - 1
Dim zero as integer = 0
'retstr &= Convert.ToString(Convert.ToChar(HBytes(i)))
retstr &= Convert.toString(zero Or HBytes(i))
Next
Return retstr
End Function

This should be simple but I've spent a lot of time going through SDK
docs but to no good.

TIA,
JS

May 17 '06 #5
Hello kenny,

Your string seems to represent UTF-16 encoded characters, but you are converting somehow as if it was UTF-8.
Your code should look like this:

Dim intIndex As Integer
Dim b() As Byte
Dim s As String
Dim file As System.IO.StreamWriter

ReDim b(Len(outputhex) \ 2)
For intIndex = 1 To Len(outputhex) Step 2
b(intIndex \ 2) = Convert.ToByte(Mid(outputhex, intIndex, 2), 16)
Next
s = System.Text.Encoding.Unicode.GetString(b)

file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
file.Write(s)
file.Close()

Regards.
"kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:35**********************************@microsof t.com...
|I have a String outputhex which consists of unicodetext translated into hex.
| example: test = 7400650073007400
|
| now i translate each two characters of the hexstring (outputhex) into byte
| and then into chars. but this is the point where something is wrong...
| (having the byteorder mark removed would also be very good)
|
| "Schließen" gets to "Schlie鿃攀渀" and so on...
|
|
|
| Here is the code:
|
| Dim intIndex As Short
| Dim j As Integer
| Dim ch As Char
|
| Dim file As System.IO.StreamWriter
| file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
|
| For intIndex = 1 To Len(outputhex) Step 2
| j = CByte("&H" & Mid(outputhex, intIndex, 2))
| ch = Convert.ToChar(j)
| file.Write(ch)
| Next
|
| file.Close()
|
|
|
|
| Thanks for the help, its urgent
May 17 '06 #6
found this:
http://groups.google.com/group/micro...13e9094151a8/#

Found a Hex function which converts a Byte or Integer or Short or Long
or Object to a Hexadecimal string
ms-help://MS.NETFrameworkSDKv1.1/vblr7net/html/vafctHex.htm

However,
common md5 databases give different results:
"standard" --> c00f0c4675b91fb8b918e4079a0b1bac

VB.Net code:
"standard" --> 92172E213F3179EB749BE8FF3D4C2B8F

what could be wrong?

My code is:
Public Function MD5String(vData As String) As String
Dim DBytes(vData.Length) As Byte, i As Integer
For i = 0 To vData.Length - 1
DBytes(i) = Convert.ToByte(Convert.ToChar(vData.Substring(i, 1)))
Next
Dim md5 As New MD5CryptoServiceProvider()
Dim HBytes As Byte() = md5.computeHash(DBytes)
Dim retstr As String
retstr = ""
For i = 0 To HBytes.Length - 1
retstr &= Hex(HBytes(i))
Next
Return retstr
End Function
TIA,
JS

May 17 '06 #7
"Brian Henry" <no****@nospam.com> wrote in message
news:eR**************@TK2MSFTNGP03.phx.gbl...
yes they are unicode... you need to translate the text format to accept
standard ASCII


Thanks. I appreciate it.

--
Charles Appel
http://charlesappel.home.mindspring.com/
Home of Chuck's Poker Libraries for Delphi,
Chuck's Video Poker and Chuck's Toys
May 17 '06 #8
No, it is UTF-8...but there are also other characters...not only unicode. Is
there a way to write them to a file independent from the encoding?? I tried
BinaryWriter but it seems also to need an encoding specified to write
correctly. I just want to write any data to a file....

"José Manuel Agüero" schrieb:
Hello kenny,

Your string seems to represent UTF-16 encoded characters, but you are converting somehow as if it was UTF-8.
Your code should look like this:

Dim intIndex As Integer
Dim b() As Byte
Dim s As String
Dim file As System.IO.StreamWriter

ReDim b(Len(outputhex) \ 2)
For intIndex = 1 To Len(outputhex) Step 2
b(intIndex \ 2) = Convert.ToByte(Mid(outputhex, intIndex, 2), 16)
Next
s = System.Text.Encoding.Unicode.GetString(b)

file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
file.Write(s)
file.Close()

Regards.
"kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:35**********************************@microsof t.com...
|I have a String outputhex which consists of unicodetext translated into hex.
| example: test = 7400650073007400
|
| now i translate each two characters of the hexstring (outputhex) into byte
| and then into chars. but this is the point where something is wrong...
| (having the byteorder mark removed would also be very good)
|
| "Schließen" gets to "Schlie鿃攀渀" and so on...
|
|
|
| Here is the code:
|
| Dim intIndex As Short
| Dim j As Integer
| Dim ch As Char
|
| Dim file As System.IO.StreamWriter
| file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
|
| For intIndex = 1 To Len(outputhex) Step 2
| j = CByte("&H" & Mid(outputhex, intIndex, 2))
| ch = Convert.ToChar(j)
| file.Write(ch)
| Next
|
| file.Close()
|
|
|
|
| Thanks for the help, its urgent

May 17 '06 #9
It doesn't exist such thing as writing a file with independence from the encoding. A file holds binary data. How that data represents text characters or other things depends on the encoding you select.
What exactly do you want to do? Write and read text in a file? Serialize objects? Write and read binary data?

By the way, OpenTextFileWriter defaults to ASCII encoding. You may use OpenTextFileWriter("test.uni", True, System.Text.Encoding.Unicode) to be able to store all characters.

Regards.
"kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:0F**********************************@microsof t.com...
| No, it is UTF-8...but there are also other characters...not only unicode. Is
| there a way to write them to a file independent from the encoding?? I tried
| BinaryWriter but it seems also to need an encoding specified to write
| correctly. I just want to write any data to a file....
|
| "José Manuel Agüero" schrieb:
|
| > Hello kenny,
| >
| > Your string seems to represent UTF-16 encoded characters, but you are converting somehow as if it was UTF-8.
| > Your code should look like this:
| >
| > Dim intIndex As Integer
| > Dim b() As Byte
| > Dim s As String
| > Dim file As System.IO.StreamWriter
| >
| > ReDim b(Len(outputhex) \ 2)
| > For intIndex = 1 To Len(outputhex) Step 2
| > b(intIndex \ 2) = Convert.ToByte(Mid(outputhex, intIndex, 2), 16)
| > Next
| > s = System.Text.Encoding.Unicode.GetString(b)
| >
| > file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > file.Write(s)
| > file.Close()
| >
| > Regards.
| >
| >
| > "kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:35**********************************@microsof t.com...
| > |I have a String outputhex which consists of unicodetext translated into hex.
| > | example: test = 7400650073007400
| > |
| > | now i translate each two characters of the hexstring (outputhex) into byte
| > | and then into chars. but this is the point where something is wrong...
| > | (having the byteorder mark removed would also be very good)
| > |
| > | "Schließen" gets to "Schlie鿃攀渀" and so on...
| > |
| > |
| > |
| > | Here is the code:
| > |
| > | Dim intIndex As Short
| > | Dim j As Integer
| > | Dim ch As Char
| > |
| > | Dim file As System.IO.StreamWriter
| > | file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > |
| > | For intIndex = 1 To Len(outputhex) Step 2
| > | j = CByte("&H" & Mid(outputhex, intIndex, 2))
| > | ch = Convert.ToChar(j)
| > | file.Write(ch)
| > | Next
| > |
| > | file.Close()
| > |
| > |
| > |
| > |
| > | Thanks for the help, its urgent

May 17 '06 #10
If I use unicode encoding then all characters are displayed correcty but
there are too much null bytes between them.
Example:
normal: S c h l i e ß e n

modified: S c h l i e ß e n

"José Manuel Agüero" wrote:
It doesn't exist such thing as writing a file with independence from the encoding. A file holds binary data. How that data represents text characters or other things depends on the encoding you select.
What exactly do you want to do? Write and read text in a file? Serialize objects? Write and read binary data?

By the way, OpenTextFileWriter defaults to ASCII encoding. You may use OpenTextFileWriter("test.uni", True, System.Text.Encoding.Unicode) to be able to store all characters.

Regards.
"kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:0F**********************************@microsof t.com...
| No, it is UTF-8...but there are also other characters...not only unicode. Is
| there a way to write them to a file independent from the encoding?? I tried
| BinaryWriter but it seems also to need an encoding specified to write
| correctly. I just want to write any data to a file....
|
| "José Manuel Agüero" schrieb:
|
| > Hello kenny,
| >
| > Your string seems to represent UTF-16 encoded characters, but you are converting somehow as if it was UTF-8.
| > Your code should look like this:
| >
| > Dim intIndex As Integer
| > Dim b() As Byte
| > Dim s As String
| > Dim file As System.IO.StreamWriter
| >
| > ReDim b(Len(outputhex) \ 2)
| > For intIndex = 1 To Len(outputhex) Step 2
| > b(intIndex \ 2) = Convert.ToByte(Mid(outputhex, intIndex, 2), 16)
| > Next
| > s = System.Text.Encoding.Unicode.GetString(b)
| >
| > file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > file.Write(s)
| > file.Close()
| >
| > Regards.
| >
| >
| > "kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:35**********************************@microsof t.com...
| > |I have a String outputhex which consists of unicodetext translated into hex.
| > | example: test = 7400650073007400
| > |
| > | now i translate each two characters of the hexstring (outputhex) into byte
| > | and then into chars. but this is the point where something is wrong...
| > | (having the byteorder mark removed would also be very good)
| > |
| > | "Schließen" gets to "Schlie鿃攀渀" and so on...
| > |
| > |
| > |
| > | Here is the code:
| > |
| > | Dim intIndex As Short
| > | Dim j As Integer
| > | Dim ch As Char
| > |
| > | Dim file As System.IO.StreamWriter
| > | file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > |
| > | For intIndex = 1 To Len(outputhex) Step 2
| > | j = CByte("&H" & Mid(outputhex, intIndex, 2))
| > | ch = Convert.ToChar(j)
| > | file.Write(ch)
| > | Next
| > |
| > | file.Close()
| > |
| > |
| > |
| > |
| > | Thanks for the help, its urgent

May 17 '06 #11
Are you really sure that the bytes represent text that is encoded as
UTF8? The example you show is clearly UTF16.

kenny wrote:
If I use unicode encoding then all characters are displayed correcty but
there are too much null bytes between them.
Example:
normal: S c h l i e ß e n

modified: S c h l i e ß e n

"José Manuel Agüero" wrote:
It doesn't exist such thing as writing a file with independence from the encoding. A file holds binary data. How that data represents text characters or other things depends on the encoding you select.
What exactly do you want to do? Write and read text in a file? Serialize objects? Write and read binary data?

By the way, OpenTextFileWriter defaults to ASCII encoding. You may use OpenTextFileWriter("test.uni", True, System.Text.Encoding.Unicode) to be able to store all characters.

Regards.
"kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:0F**********************************@microsof t.com...
| No, it is UTF-8...but there are also other characters...not only unicode. Is
| there a way to write them to a file independent from the encoding?? I tried
| BinaryWriter but it seems also to need an encoding specified to write
| correctly. I just want to write any data to a file....
|
| "José Manuel Agüero" schrieb:
|
| > Hello kenny,
| >
| > Your string seems to represent UTF-16 encoded characters, but you are converting somehow as if it was UTF-8.
| > Your code should look like this:
| >
| > Dim intIndex As Integer
| > Dim b() As Byte
| > Dim s As String
| > Dim file As System.IO.StreamWriter
| >
| > ReDim b(Len(outputhex) \ 2)
| > For intIndex = 1 To Len(outputhex) Step 2
| > b(intIndex \ 2) = Convert.ToByte(Mid(outputhex, intIndex, 2), 16)
| > Next
| > s = System.Text.Encoding.Unicode.GetString(b)
| >
| > file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > file.Write(s)
| > file.Close()
| >
| > Regards.
| >
| >
| > "kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:35**********************************@microsof t.com...
| > |I have a String outputhex which consists of unicodetext translated into hex.
| > | example: test = 7400650073007400
| > |
| > | now i translate each two characters of the hexstring (outputhex) into byte
| > | and then into chars. but this is the point where something is wrong...
| > | (having the byteorder mark removed would also be very good)
| > |
| > | "Schließen" gets to "Schlie鿃攀渀" and so on...
| > |
| > |
| > |
| > | Here is the code:
| > |
| > | Dim intIndex As Short
| > | Dim j As Integer
| > | Dim ch As Char
| > |
| > | Dim file As System.IO.StreamWriter
| > | file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > |
| > | For intIndex = 1 To Len(outputhex) Step 2
| > | j = CByte("&H" & Mid(outputhex, intIndex, 2))
| > | ch = Convert.ToChar(j)
| > | file.Write(ch)
| > | Next
| > |
| > | file.Close()
| > |
| > |
| > |
| > |
| > | Thanks for the help, its urgent

May 17 '06 #12
Hmmm, yes...you are right! But i still don't know how to get dir of all these
null bytes...

"Göran Andersson" wrote:
Are you really sure that the bytes represent text that is encoded as
UTF8? The example you show is clearly UTF16.

May 17 '06 #13
> Dim DBytes(vData.Length) As Byte, i As Integer
^^^^^^^^^^^^

Should be vData.Length - 1, or your buffer will be one byte too long
which I guess affects the computed hash.

For i = 0 To vData.Length - 1
DBytes(i) = Convert.ToByte(Convert.ToChar(vData.Substring(i, 1)))
Next
If you expect the input to be all ASCII you can use the
System.Text.ASCIIEncoding to convert the input string to a byte array.

For i = 0 To HBytes.Length - 1
retstr &= Hex(HBytes(i))
Next


You probably want to zero pad the returned string to ensure that each
byte gets represented by two characters.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 17 '06 #14
It seems that you're writing using UTF-16 and reading using UTF-8 (or UTF-7 or ASCII). Review your code and keep the same encoding when accesing the same data.

Regards.
"kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:EF**********************************@microsof t.com...
| If I use unicode encoding then all characters are displayed correcty but
| there are too much null bytes between them.
| Example:
| normal: S c h l i e ß e n
|
| modified: S c h l i e ß e n
|
| "José Manuel Agüero" wrote:
|
| > It doesn't exist such thing as writing a file with independence from the encoding. A file holds binary data. How that data represents text characters or other things depends on the encoding you select.
| > What exactly do you want to do? Write and read text in a file? Serialize objects? Write and read binary data?
| >
| > By the way, OpenTextFileWriter defaults to ASCII encoding. You may use OpenTextFileWriter("test.uni", True, System.Text.Encoding.Unicode) to be able to store all characters.
| >
| > Regards.
| >
| >
| > "kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:0F**********************************@microsof t.com...
| > | No, it is UTF-8...but there are also other characters...not only unicode. Is
| > | there a way to write them to a file independent from the encoding?? I tried
| > | BinaryWriter but it seems also to need an encoding specified to write
| > | correctly. I just want to write any data to a file....
| > |
| > | "José Manuel Agüero" schrieb:
| > |
| > | > Hello kenny,
| > | >
| > | > Your string seems to represent UTF-16 encoded characters, but you are converting somehow as if it was UTF-8.
| > | > Your code should look like this:
| > | >
| > | > Dim intIndex As Integer
| > | > Dim b() As Byte
| > | > Dim s As String
| > | > Dim file As System.IO.StreamWriter
| > | >
| > | > ReDim b(Len(outputhex) \ 2)
| > | > For intIndex = 1 To Len(outputhex) Step 2
| > | > b(intIndex \ 2) = Convert.ToByte(Mid(outputhex, intIndex, 2), 16)
| > | > Next
| > | > s = System.Text.Encoding.Unicode.GetString(b)
| > | >
| > | > file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > | > file.Write(s)
| > | > file.Close()
| > | >
| > | > Regards.
| > | >
| > | >
| > | > "kenny" <ke***@discussions.microsoft.com> escribió en el mensaje news:35**********************************@microsof t.com...
| > | > |I have a String outputhex which consists of unicodetext translated into hex.
| > | > | example: test = 7400650073007400
| > | > |
| > | > | now i translate each two characters of the hexstring (outputhex) into byte
| > | > | and then into chars. but this is the point where something is wrong...
| > | > | (having the byteorder mark removed would also be very good)
| > | > |
| > | > | "Schließen" gets to "Schlie鿃攀渀" and so on...
| > | > |
| > | > |
| > | > |
| > | > | Here is the code:
| > | > |
| > | > | Dim intIndex As Short
| > | > | Dim j As Integer
| > | > | Dim ch As Char
| > | > |
| > | > | Dim file As System.IO.StreamWriter
| > | > | file = My.Computer.FileSystem.OpenTextFileWriter("test.un i", True)
| > | > |
| > | > | For intIndex = 1 To Len(outputhex) Step 2
| > | > | j = CByte("&H" & Mid(outputhex, intIndex, 2))
| > | > | ch = Convert.ToChar(j)
| > | > | file.Write(ch)
| > | > | Next
| > | > |
| > | > | file.Close()
| > | > |
| > | > |
| > | > |
| > | > |
| > | > | Thanks for the help, its urgent
| >
| >
May 17 '06 #15
As the data is UTF16 you don't need to decode it. Just convert the
values in the string to char values.

string test = "7400650073007400";

char[] data = new char[test.Length / 4];
int pos = 0;
for (int i=0; i<data.Length; i++) {
data[i] = (char)(
((int)test[pos++] - 48) * 16 +
((int)test[pos++] - 48) +
((int)test[pos++] - 48) * 4096 +
((int)test[pos++] - 48) * 256
);
}

string result = new String(data);

[Disclaimer: untested code]
kenny wrote:
Hmmm, yes...you are right! But i still don't know how to get dir of all these
null bytes...

"Göran Andersson" wrote:
Are you really sure that the bytes represent text that is encoded as
UTF8? The example you show is clearly UTF16.

May 18 '06 #16
Hi, thanks for the clarifications, its now working.
Mattias Sjögren wrote:
Dim DBytes(vData.Length) As Byte, i As Integer

^^^^^^^^^^^^
Should be vData.Length - 1, or your buffer will be one byte too long
which I guess affects the computed hash.


I have a book which says that
Dim a(30) as Integer
has 30 objects from a(0) to a(29).

However, I tested it and found that
Dim a(30) as Integer
has _31_ objects from a(0) to a(30)

Is there some kind of system-level setting or is it a mistake in the
book?
Or am I missing something obvious?
For i = 0 To HBytes.Length - 1
retstr &= Hex(HBytes(i))
Next


You probably want to zero pad the returned string to ensure that each
byte gets represented by two characters.

Yes, I had to zero pad the hex strings.

Regards,
JS

May 19 '06 #17
Joseph S. wrote:
Hi, thanks for the clarifications, its now working.
Mattias Sjögren wrote:
Dim DBytes(vData.Length) As Byte, i As Integer

^^^^^^^^^^^^
Should be vData.Length - 1, or your buffer will be one byte too long
which I guess affects the computed hash.


I have a book which says that
Dim a(30) as Integer
has 30 objects from a(0) to a(29).

However, I tested it and found that
Dim a(30) as Integer
has _31_ objects from a(0) to a(30)

Is there some kind of system-level setting or is it a mistake in the
book?
Or am I missing something obvious?


It's definitely a mistake in the book.

In VB you specify the highest index to use in the array, not the number
of items. This is differnt from most other languages, where you specify
the number of items instead.

C# example:

int[] a = new int[30]; // creates an array with 30 items.
For i = 0 To HBytes.Length - 1
retstr &= Hex(HBytes(i))
Next

You probably want to zero pad the returned string to ensure that each
byte gets represented by two characters.

Yes, I had to zero pad the hex strings.

Regards,
JS

May 19 '06 #18
Joseph S. wrote:
Hi, thanks for the clarifications, its now working.
Mattias Sjögren wrote:
Dim DBytes(vData.Length) As Byte, i As Integer


^^^^^^^^^^^^
Should be vData.Length - 1, or your buffer will be one byte too long
which I guess affects the computed hash.

I have a book which says that
Dim a(30) as Integer
has 30 objects from a(0) to a(29).

However, I tested it and found that
Dim a(30) as Integer
has _31_ objects from a(0) to a(30)

Is there some kind of system-level setting or is it a mistake in the
book?
Or am I missing something obvious?

For i = 0 To HBytes.Length - 1
retstr &= Hex(HBytes(i))
Next


You probably want to zero pad the returned string to ensure that each
byte gets represented by two characters.


Yes, I had to zero pad the hex strings.

Regards,
JS


The book is wrong... unless it's stated it used option base 1 (don't
know if that still exists in dotnet though, but it works in vb5/6.
Option base 1 makes the 1st index 1 instead of 0.
--
Rinze van Huizen
C-Services Holland b.v
May 19 '06 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dorthe Luebbert | last post by:
Hi, we have to convert a quite large ISO-application (Mysql4, PHP5) to UTF8. We found out so far that there is no collation for MySQL which is able to sort all character sets correctly. So this...
235
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
14
by: gamja | last post by:
Hi all. This is my first post on this group. Nice to meet you, cool guys~! I'm on system programming on various embedded systems and understand very well the byte alignment issues. When I write...
7
by: Yama | last post by:
Hi, I have the following binary data: StringData = 800006000000; which is equivalent to the following: byte bytes = new byte; bytes = 0x80;
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
8
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be...
4
by: ThunderMusic | last post by:
Hi, I have to go from Byte() to String, do some processing then reconvert the String to byte() but using ascii format, not unicode. I currently use a stream to write the char()...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
3
by: pamelafluente | last post by:
I am trying to convert in C# a VB.NET routine (which probably came from C# ! ) I need to translate using pointers (this should get the Alpha byte in a 32bppPArgb bitmap): Function...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.