Reading Hex values into UByte variable.

14 views
Skip to first unread message

abhijit kulkarni

unread,
Nov 19, 2010, 2:33:48 PM11/19/10
to coms49...@googlegroups.com
Hello,

We are trying to read Hex values and  want to convert them to UByte values. The Hex values are represented as string, for example "A2". When using the function UByte.parse("A2",16), the function throws a number format exception. What we observed was that for values up to 127 (7F) decimal it works fine, anything beyond that it fails i.e. anything beyond 7 bits is not accepted. How do I read such 8 bit values into UByte then?

Currently my project work is stalled due to this issue. Any help with this issue will be greatly appreciated.

Thanks,
Abhijit

Lewis Flanagan

unread,
Nov 19, 2010, 2:48:07 PM11/19/10
to coms49...@googlegroups.com
I'm not sure what UByte values are but the reason that you can't go over 127 is likely because the first bit of the byte is the positive or negative sign. If there is something like a "UUnsignedByte," that might give you the behavior you're looking for. 

The best,
Lewis Flanagan

Yoav Zibin

unread,
Nov 19, 2010, 2:50:20 PM11/19/10
to coms49...@googlegroups.com
UByte is unsigned :)

There is actually a bug in UByte.parse  which is pretty obvious.

Use UShort.parse and cast it to a UByte.


    @Native("c++", "((x10_ubyte) x10aux::int_utils::parseInt(#1, #2))")
    public static def parse(s:String, radix:Int): UByte //throws NumberFormatException
    {
        return UByte(Byte.parse(s, radix));

Yoav Zibin

unread,
Nov 19, 2010, 2:53:59 PM11/19/10
to coms49...@googlegroups.com
I opened a jira for it:
http://jira.codehaus.org/browse/XTENLANG-2119
but it won't be fixed in the version you're using :)

Pranay Prabhakar

unread,
Nov 19, 2010, 4:50:32 PM11/19/10
to coms49...@googlegroups.com, Yoav Zibin, amk...@columbia.edu

The casting worked. Thank you.

Pranay, Abhijit

Reply all
Reply to author
Forward
0 new messages