Problem with UShort.parse() method on x10 - 2.1.0

25 views
Skip to first unread message

abhijit kulkarni

unread,
Dec 2, 2010, 2:47:06 PM12/2/10
to coms49...@googlegroups.com, Pranay Prabhakar
Hi,

I am using x10 2.1.0 to compile my project code.
I am calling UShort.parse(<string>, 16) function to convert hex string into UShort.
It seems that this function is returning UShort value 16 irrespective of the input.

I tried to run below code on x10 2.0.6 and x10 2.1.0 -
str : String = "ff";
ub : UByte = UByte.operator_as(UShort.parse(str, 16));
Console.OUT.println(ub);
Console.OUT.println(UShort.parse(str, 16));

On x10 2.0.6, the output is -
255
255
On x10 2.1.0, the output is 16 (irrespective of any input string value)
16
16

I need this function as I am not able to proceed without it for my project.

Thanks for your help.


Regards,
Abhijit
 

Yoav Zibin

unread,
Dec 2, 2010, 3:31:09 PM12/2/10
to coms49...@googlegroups.com, Pranay Prabhakar
Maybe try to use:
Int.parse
and then cast to UShort.

Pranay Prabhakar

unread,
Dec 2, 2010, 4:20:47 PM12/2/10
to Yoav Zibin, amk...@columbia.edu, coms49...@googlegroups.com

We tried using Int.parse("ff",16), the result is the same, i.e. 16. We are trying to implement a byte level encryption for which we need to read Hex strings into UBytes. Is there a tested way to proceed with this?

Thanks,

Pranay

Yoav Zibin

unread,
Dec 2, 2010, 4:24:39 PM12/2/10
to Pranay Prabhakar, amk...@columbia.edu, coms49...@googlegroups.com
You can write that method yourself.
Convert this java code to X10:

private long parseLong(String s, int radix)
    {
        long x = 0L;

        s = s.toLowerCase();

        for (int i = 0; i < s.length(); i++) {
            int c = s.charAt(i);

            if (c < '0' || c > '9') {
                c = c - 'a' + 10;
            }
            else {
                c = c - '0';
            }

            x *= radix;
            x += c;
        }

        return x;

Pranay Prabhakar

unread,
Dec 2, 2010, 4:37:36 PM12/2/10
to Yoav Zibin, amk...@columbia.edu, coms49...@googlegroups.com

Thank you for the prompt reply. We have been trying to write our conversion routine, but we encounter this error:

"AESCrypto.cc:566: error: no match for âoperator-â in âch - x10_char(48)â".

The corresponding x10 code was:  u-'a', where u:Char.

Yoav Zibin

unread,
Dec 2, 2010, 4:41:15 PM12/2/10
to Pranay Prabhakar, amk...@columbia.edu, coms49...@googlegroups.com
You don't need to handle unicode, so just use the ASCII values directly
(so instead of 'a' use 97, and instead of '0' use 48, and '9' is 57.)

Abhijit Kulkarni

unread,
Dec 2, 2010, 5:06:04 PM12/2/10
to Yoav Zibin, coms49...@googlegroups.com, Pranay Prabhakar
Hi, 

I have tried doing below things -

Here, i is Int and ch is Char
case 1 : i = (ch - 48);
AESCrypto.cc:566: error: no match for âoperator-â in âch - x10_char(48)â

case 2 : i = (ch - A), where A is var A : char = 'a'
AESCrypto.cc:551: error: no match for âoperator-â in âch - Aâ

case 3 : i = (ch - 'a')
AESCrypto.cc:545: error: no match for âoperator-â in âch - x10_char(48)â

case 4 : i = Int.parse((ch - 'a').toString())
AESCrypto.cc:560: error: no match for âoperator-â in âch - x10_char(48)â


From x10 2.1.0 documentation, char has operator - defined and it returns an Int.

But I am not able to compile any of the above cases.
Please let me know how should I use this exactly.

Thanks for your help.

Regards,
Abhijit

Martha Kim

unread,
Dec 2, 2010, 5:13:42 PM12/2/10
to coms49...@googlegroups.com, Yoav Zibin, Pranay Prabhakar
Hi Abhijit,

This appears to be a typecheck error.  The problem is that you're trying to execute a subtraction on a Char type, and the error messaging is saying that they cannot find a subtraction operator for the Char type.  I'd cast (or otherwise convert) your Char to an Int, and then do the arithmetic on Ints.

Martha
Reply all
Reply to author
Forward
0 new messages