473,395 Members | 1,458 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,395 software developers and data experts.

create hex-string to send on networkstream

Hello,

I need to send a couple of "NUL"s -> HEX value "00" on a networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it's not possible to use a
string as input..
Thanks,
Sven
Nov 20 '05 #1
10 3908
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
I need to send a couple of "NUL"s -> HEX value "00" on a
networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it's not possible to
use a string as input..


Why is there no "char value"? chr(0) returns such a char. Don't use ASCII
encoding because ASCII = 7 bits. Do you want to send the character codes of
the hexadecimal string representation of the chars, or do you want to send
the character codes themselves? What is "inputtext"? What does it contain
for example?

One possible solution:
Dim sendBytes As Byte() 'no [ ] required here
sendBytes = Encoding.Default.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)

Encoding.Default returns the current ANSI codepage (8-Bit character codes).

The other solution depends on the answers to the questions above.

Maybe you can use a Streamwriter instead. You could pass the encoding once
to the constructor and don't have to convert each string on your own.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
I need to send a couple of "NUL"s -> HEX value "00" on a
networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it's not possible to
use a string as input..


Why is there no "char value"? chr(0) returns such a char. Don't use ASCII
encoding because ASCII = 7 bits. Do you want to send the character codes of
the hexadecimal string representation of the chars, or do you want to send
the character codes themselves? What is "inputtext"? What does it contain
for example?

One possible solution:
Dim sendBytes As Byte() 'no [ ] required here
sendBytes = Encoding.Default.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)

Encoding.Default returns the current ANSI codepage (8-Bit character codes).

The other solution depends on the answers to the questions above.

Maybe you can use a Streamwriter instead. You could pass the encoding once
to the constructor and don't have to convert each string on your own.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "Sven Huijbrechts" <sv**@no-spam-hts.be> scripsit:
Since there is no char value for hex 00 (NUL) it's not possible to use a

string as input..


?!?

You can use 'ControlChars.NullChar' to get a null character.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
* "Sven Huijbrechts" <sv**@no-spam-hts.be> scripsit:
Since there is no char value for hex 00 (NUL) it's not possible to use a

string as input..


?!?

You can use 'ControlChars.NullChar' to get a null character.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
When you look at this page:
ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/_pluslang_ascii_character_codes_ch
art_1.htm

The first line (Dec: 0 / Hex: 00 / Char: / Code: NUL) is the code I have to
send..
I need to send a bigendian HEX value over the networkstream.
So I want to fill the array sendBytes with '00','00','00','3E' for example.

My problem is that the string '0000003E' is converted to hex
'30','30','30','30','30','30','33','45'
And there is no string which translates to hex '00','00','00','3E'

Sven

"Armin Zingler" <az*******@freenet.de> wrote in message
news:ud*************@TK2MSFTNGP11.phx.gbl...
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
I need to send a couple of "NUL"s -> HEX value "00" on a
networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it's not possible to
use a string as input..
Why is there no "char value"? chr(0) returns such a char. Don't use ASCII
encoding because ASCII = 7 bits. Do you want to send the character codes

of the hexadecimal string representation of the chars, or do you want to send
the character codes themselves? What is "inputtext"? What does it contain
for example?

One possible solution:
Dim sendBytes As Byte() 'no [ ] required here
sendBytes = Encoding.Default.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)

Encoding.Default returns the current ANSI codepage (8-Bit character codes).
The other solution depends on the answers to the questions above.

Maybe you can use a Streamwriter instead. You could pass the encoding once
to the constructor and don't have to convert each string on your own.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
When you look at this page:
ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/_pluslang_ascii_character_codes_ch
art_1.htm

The first line (Dec: 0 / Hex: 00 / Char: / Code: NUL) is the code I have to
send..
I need to send a bigendian HEX value over the networkstream.
So I want to fill the array sendBytes with '00','00','00','3E' for example.

My problem is that the string '0000003E' is converted to hex
'30','30','30','30','30','30','33','45'
And there is no string which translates to hex '00','00','00','3E'

Sven

"Armin Zingler" <az*******@freenet.de> wrote in message
news:ud*************@TK2MSFTNGP11.phx.gbl...
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
I need to send a couple of "NUL"s -> HEX value "00" on a
networkstream..

This is the code we currently use to send string:
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Since there is no char value for hex 00 (NUL) it's not possible to
use a string as input..
Why is there no "char value"? chr(0) returns such a char. Don't use ASCII
encoding because ASCII = 7 bits. Do you want to send the character codes

of the hexadecimal string representation of the chars, or do you want to send
the character codes themselves? What is "inputtext"? What does it contain
for example?

One possible solution:
Dim sendBytes As Byte() 'no [ ] required here
sendBytes = Encoding.Default.GetBytes(inputtext.ToString)
networkStream.Write(sendBytes, 0, sendBytes.Length)

Encoding.Default returns the current ANSI codepage (8-Bit character codes).
The other solution depends on the answers to the questions above.

Maybe you can use a Streamwriter instead. You could pass the encoding once
to the constructor and don't have to convert each string on your own.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
When you look at this page:
ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/_pluslang_ascii_character_codes_ch art_1.htm

The first line (Dec: 0 / Hex: 00 / Char: / Code: NUL) is the code I
have to send..
I need to send a bigendian HEX value over the networkstream.
So I want to fill the array sendBytes with '00','00','00','3E' for
example.

My problem is that the string '0000003E' is converted to hex
'30','30','30','30','30','30','33','45'
And there is no string which translates to hex '00','00','00','3E'


You say the string to be sent is "0000003E"? If yes:
Dim s As String = "0000003E"
Dim b As Byte()
Dim i As Integer

ReDim b(s.Length \ 2 - 1)

For i = 0 To s.Length Step 2
b(i \ 2) = Convert.ToByte(s.Substring(i, 2), 16)
Next

If it is always 8 chars in the source string (representing an Integer):

b = BitConverter.GetBytes(Convert.ToInt32(s, 16)).

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
When you look at this page:
ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/_pluslang_ascii_character_codes_ch art_1.htm

The first line (Dec: 0 / Hex: 00 / Char: / Code: NUL) is the code I
have to send..
I need to send a bigendian HEX value over the networkstream.
So I want to fill the array sendBytes with '00','00','00','3E' for
example.

My problem is that the string '0000003E' is converted to hex
'30','30','30','30','30','30','33','45'
And there is no string which translates to hex '00','00','00','3E'


You say the string to be sent is "0000003E"? If yes:
Dim s As String = "0000003E"
Dim b As Byte()
Dim i As Integer

ReDim b(s.Length \ 2 - 1)

For i = 0 To s.Length Step 2
b(i \ 2) = Convert.ToByte(s.Substring(i, 2), 16)
Next

If it is always 8 chars in the source string (representing an Integer):

b = BitConverter.GetBytes(Convert.ToInt32(s, 16)).

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
When you look at this page:
ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/_pluslang_ascii_character_codes_ch art_1.htm

The first line (Dec: 0 / Hex: 00 / Char: / Code: NUL) is the code I
have to send..
I need to send a bigendian HEX value over the networkstream.
So I want to fill the array sendBytes with '00','00','00','3E' for
example.

My problem is that the string '0000003E' is converted to hex
'30','30','30','30','30','30','33','45'
And there is no string which translates to hex '00','00','00','3E'


You say the string to be sent is "0000003E"? If yes:
Dim s As String = "0000003E"
Dim b As Byte()
Dim i As Integer

ReDim b(s.Length \ 2 - 1)

For i = 0 To s.Length Step 2
b(i \ 2) = Convert.ToByte(s.Substring(i, 2), 16)
Next

If it is always 8 chars in the source string (representing an Integer):

b = BitConverter.GetBytes(Convert.ToInt32(s, 16)).
......
I forgot: In the first example the byte order must be reversed.
To reverse an existing array, use Array.Reverse.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10
thanks for the info..
I'll have a look at it soon, currently other priorities..

Greetings,
Sven
"Armin Zingler" <az*******@freenet.de> wrote in message
news:ug*************@TK2MSFTNGP11.phx.gbl...
"Sven Huijbrechts" <sv**@no-spam-hts.be> schrieb
When you look at this page:

ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/_pluslang_ascii_character_codes_ch
art_1.htm

The first line (Dec: 0 / Hex: 00 / Char: / Code: NUL) is the code I
have to send..
I need to send a bigendian HEX value over the networkstream.
So I want to fill the array sendBytes with '00','00','00','3E' for
example.

My problem is that the string '0000003E' is converted to hex
'30','30','30','30','30','30','33','45'
And there is no string which translates to hex '00','00','00','3E'


You say the string to be sent is "0000003E"? If yes:
Dim s As String = "0000003E"
Dim b As Byte()
Dim i As Integer

ReDim b(s.Length \ 2 - 1)

For i = 0 To s.Length Step 2
b(i \ 2) = Convert.ToByte(s.Substring(i, 2), 16)
Next

If it is always 8 chars in the source string (representing an Integer):

b = BitConverter.GetBytes(Convert.ToInt32(s, 16)).
.....
I forgot: In the first example the byte order must be reversed.
To reverse an existing array, use Array.Reverse.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #11

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

Similar topics

5
by: DvGrimm | last post by:
Any help would be very, very much appreciated... I've been searching the net (google) for 4 days now trying to find a php function to convert hex to floating point. I'm converting old...
4
by: Paul | last post by:
Hi, (First apologies if this is not the most relevant place to post this but I wasn't sure of where was and I am writing my app in VB.) I'm attempting to parse a binary file for which I have...
16
by: Delali Dzirasa | last post by:
I would have a number packed with its hex representation of the integer below is some sample code of what is being done. int value = 20; //in hex it is 0x14 AddData (value); .. .. ..
7
by: Steven D'Aprano | last post by:
hex() of an int appears to return lowercase hex digits, and hex() of a long uppercase. >>> hex(75) '0x4b' >>> hex(75*256**4) '0x4B00000000L' By accident or design? Apart from the aesthetic...
6
by: Luther Baker | last post by:
Hi, This doesn't do what I expect. int t = 27; std::cout << "myHex: '" << std::ios::hex << t << "'" << std::endl; std::cout.setf(std::ios::hex); std::cout << "moreHex: '" << t << "'" <<...
2
by: Generic Usenet Account | last post by:
What exactly is the difference between the hex manipulator and the following statement: cout.setf(ios_base::hex)? According to Stroustrup, Third Edition, Section 21.4.4, "once set, a base is...
5
by: kuukelekuu | last post by:
I need to convert ascii chars to hex chars. I searched the internet, found hex to ascii, but nowhere is there a ascii to hex method created by anyone. Can anyone help me with that? Chears
28
by: James Brown | last post by:
All, I have a series of characters which I need to convert to integer values. Each character is read in turn from a function 'nextch', and hex-digits are identified by the isxdigit function - so...
9
by: twang090 | last post by:
Trying to create a 12 digit "guid", but have no idea on how to, anyone please have any thought? Thanks in advance.
4
by: kelly86 | last post by:
hi guys im stuck here...actually i was asked 2 use C language to create a hex reader/compiler/editor, for use in test department for modifying *.bin files. Well as a new trainee in this company i...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.