By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

hex sending

P: n/a
s.send("abc") # send test string

I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"

hoW?

Oct 4 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"hiroc" wrote:
s.send("abc") # send test string

I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"
do you want to send seven binary bytes, or pairs of hexadecimal characters
separated by whitespace ?

how do you map from "abc" to "10 06 00 0f 02 bc d1", by the way? what
encoding is that?

</F>

Oct 4 '06 #2

P: n/a
I want send pairs of hexadecimal characters, abc is only my test hex
char is real

Fredrik Lundh wrote:
"hiroc" wrote:
s.send("abc") # send test string

I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"

do you want to send seven binary bytes, or pairs of hexadecimal characters
separated by whitespace ?

how do you map from "abc" to "10 06 00 0f 02 bc d1", by the way? what
encoding is that?

</F>
Oct 4 '06 #3

P: n/a

hiroc wrote:
I want send pairs of hexadecimal characters, abc is only my test hex
char is real
Possibly this code helps to you:

import binascii

binascii.hexlify('hello worlds')

Output: '68656c6c6f20776f726c6473'

Oct 4 '06 #4

P: n/a
"hiroc" <hi*****@hotmail.comwrote:
>s.send("abc") # send test string

I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"

hoW?
One ugly way is
s.send( "\x10\x06\x00\x0f\x02\xbc\xd1" )
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 5 '06 #5

P: n/a
"hiroc" <hi*****@hotmail.comwrites:
s.send("abc") # send test string
I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"
See the binascii module:

import binascii

# a2b_hex stands for "ascii to binary conversion, hex format"
# you must remove the spaces
binary = binascii.a2b_hex ("1006000f02bcd1")

s.send (binary)
Oct 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.