Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

problem in finding character

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class TestByte {

public static void main(String[] args) {
byte u[] = new byte[1999];
char pc ='?';
char t ='@';
char c = 0xfff1;
setPageControl((char) (-15 & 0x0000ffff));
setPageControl((char) (-16 & 0x0000ffff));
}

static void setPageControl(char pc)
{

if(pc == 0xfff0)
{
System.out.println("inside 0xfff0 question mark");
}
if(pc == 0xfff1)
{
System.out.println("inside 0xfff1 question mark");
}

}
}

can anybody help me in understanding this?if i print the character it prints '?' in both the SOPS.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly are you trying to do?

When you compare the char with the int, the char will be promoted to an int.

As an int, '?' is 63 which is not equal to 0x0000FFF0 nor to 0x0000FFF1.
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anitha Ramanujam:
can anybody help me in understanding this?if i print the character it prints '?' in both the SOPS.[/QB]



(char) (-15 & 0x0000ffff) is 0xfff1
(char) (-16 & 0x0000ffff) is 0xfff0

you are calling setPageControl twice,.. first time with parameter 0xfff1, which prints "inside fff1..", second time with parameter 0xfff0 and this prints "inside fff0"

It is not printing the both messages in one call of setPageControl, if this is what troubles you.
[ May 10, 2007: Message edited by: John Stone ]
 
Anitha Ramanujam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi john.thanks for the response.but my doubt is (char) (-15 & 0x0000ffff)
how doues this value in char be oxfff0
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just take a look at binary form of these two numbers:

11111111111111111111111111110001 (-15)
00000000000000001111111111111111 (0xffff)
& ---------------------------------
00000000000000001111111111110001 (0xfff0)

if you don't understand the form of 2's complementary (I mean you wonder why this bits for -15 are as they are), just google for some doc or wiki
e.g. http://compsci.ucd.ie/staff/jcarthy/home/FirstYear/Comp1001-L4-L5.pdf
page 19, 20
 
Whatever. Here's a tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic