• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 993
  • Last Modified:

Java char value assignments

Hi,

I am porting a Java project which makes some strange assignments of int values in a function.  I have been Googling this for a while but have not figured it out.

The char c is being passed to the setX function which has a single int parameter.  So why has the original coder used a char instead of int?  The 'else' segment seems to assign an invalid unicode character to the char.  I don't know what c = '\210' does (decimal 210 is Ò).

Sorry the code fragment is so terse, there's not a lot of surrounding code to post.
char c;
if (xPos < 100) {
  c = '\210';
} 
else {
  c = '\uFFF8';
}
obj.setX(c);
 
 
// this is the definition of obj.setX
public void setX(int i)

Open in new window

0
falmon
Asked:
falmon
  • 2
  • 2
1 Solution
 
josepvallsCommented:
Java will automatically cast the int value of a character.
Are you sure the int value of '\210' is what you want?
0
 
falmonAuthor Commented:
Well - I am trying to work out what the code does so that I can replicate its behavior in AS3.  So I'm not sure that I want the int value of '\210'.  I am still baffled as to why he decided to create a char, assign it odd values, and then pass it into a function which will cast it as int.  The char isn't used elsewhere.

My assumption was that since "char c = '\uFFF8';" will create a single Unicode character (http://www.fileformat.info/info/unicode/char/fff8/index.htm - possibly... it doesn't even seem to be a valid char) his '\210' assignment would perhaps assign a Unicode char by decimal value?

I guess my question is - what values would I expect as the integer argument to setX for each part of the conditional, given the char values set, and is there any clear reason that the original coder decided to use a char in this way?
0
 
josepvallsCommented:
Forget about the char. Replace it for an int.
'\210' replace it with 136 and '\uFFF8' with 65528.
Those are the int values that are being passed to that function.
Now, your question about why those two values is a whole different issue.
Can't be answered without some more reference about the application.
0
 
falmonAuthor Commented:
OK, that's very useful in terms of how the casting works and basically answers the question!!
Never would have expected those int castings coming from a PHP/JS/AS background.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now