How do I send HEX numbers across TCP?

J

Jerry Spence1

I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead of
the hex values.

Can anyone help please?

-Jerry
 
M

Michel Vanderbeke

Hello,

jim said:
nevermind.....I got it.

Can you please post how you are doing this? I am trying to determine if a PC
is connected to a certain netwoek.

Thanks,

Michel
 
A

AlexS

How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?
 
J

Jerry Spence1

Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual Hex
values, rather than the string itself. It's the difference between sending
FFh (ie 11111111) and "FF" (which will send the ascii values for FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


Jerry Spence1 said:
I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead of
the hex values.

Can anyone help please?

-Jerry
 
B

Blake

Jerry Spence1 said:
Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual
Hex values, rather than the string itself. It's the difference between
sending FFh (ie 11111111) and "FF" (which will send the ascii values for
FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


Jerry Spence1 said:
I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead
of the hex values.

Can anyone help please?

-Jerry

something like this?...

Dim mydata() As Byte = New Byte(0 To 7) { _
&H1, &HFF, &HF1, &H55, &H1, &HFF, &HFF, &H0}

Send(mydata)




-Blake
 
A

AlexS

This should work:

dim sendBytes() as Byte = { &Hff, &H01, &H00, &H40, ... }

networkStream.Write(sendBytes, 0, sendBytes.Length)


Jerry Spence1 said:
Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual
Hex values, rather than the string itself. It's the difference between
sending FFh (ie 11111111) and "FF" (which will send the ascii values for
FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


Jerry Spence1 said:
I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead
of the hex values.

Can anyone help please?

-Jerry
 
J

Jerry Spence1

Blake said:
Jerry Spence1 said:
Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual
Hex values, rather than the string itself. It's the difference between
sending FFh (ie 11111111) and "FF" (which will send the ascii values for
FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() =
System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead
of the hex values.

Can anyone help please?

-Jerry

something like this?...

Dim mydata() As Byte = New Byte(0 To 7) { _
&H1, &HFF, &HF1, &H55, &H1, &HFF, &HFF, &H0}

Send(mydata)




-Blake

Thank you Blake and Alex. That was it. Very grateful

-Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top