David is exactly right. If you're seeing a \t, it's because the string is
being output in string-escape encoding. For the codec support, see
http://www.jython.org/docs/library/codecs.html#standard-encodings (note,
this doc is not quite right, we don't support the East Asian codecs in
Jython itself until 2.6, but they are available in Java itself).
If you want a byte array, as in something that you could pass to a Java
method wanting a byte[] arg, use the array module:
>>> import array
>>> array.array('b',
'0109053901101232FFFFFF020A8981300999999000'.decode('hex'))
array('b', [1, 9, 5, 57, 1, 16, 18, 50, -1, -1, -1, 2, 10, -119, -127, 48,
9, -103, -103, -112, 0])
On Fri, Aug 13, 2010 at 9:01 AM, David Handy <Dav...@sa...> wrote:
> It’s Ok. “\t” means the tab character, which is ascii code 9. So your
> conversion is probably working correctly.
>
>
>
> *From:* Greg78 [mailto:gre...@ho...]
> *Sent:* Friday, August 13, 2010 5:08 AM
> *To:* jyt...@li...
> *Subject:* [Jython-users] convert hex byte string into byte array
>
>
>
> Hello, I would like to convert a hex byte string into a byte array ; Here
> is an example : hex byte string :
> "0109053901101232FFFFFF020A89813009999990000" and I would like to have as a
> result :
> "\x01\x09\x05\x39\x01\x10\x12\x32\xFF\xFF\xFF\x02\x0A\x89\x81\x30\x09\x99\x99\x90\x00\"
> I found some functions but I have problem with some bytes like "09" which is
> converted into "\t" Thanks in advance for help Greg
> ------------------------------
>
> View this message in context: convert hex byte string into byte array<http://old.nabble.com/convert-hex-byte-string-into-byte-array-tp29426914p29426914.html>
> Sent from the jython-users mailing list archive<http://old.nabble.com/jython-users-f4123.html>at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
>
|