LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-08-2008, 07:10 AM   #1
sharathkv
Member
 
Registered: Jul 2003
Distribution: HP-UX
Posts: 35

Rep: Reputation: 15
Convert C++ to Java


Hi,

I have a program, which I converted to Java from C++. At least most of it. However I am getting error for 2 statements. Any help would be appreciated;

This is the error I am getting:
Code:
$ javac FirmwareTest.java
FirmwareTest.java:56: operator ! cannot be applied to int
                if ((len != 270) || (s0.charAt(0) != 0x83) || (!(b1 & 0x80) ) ) {
                                                               ^
FirmwareTest.java:80: cannot resolve symbol
symbol  : method subString  (int)
location: class java.lang.String
                        String strRev1 = pHead.subString(3);
                                              ^
2 errors
How to re-write this expression in Java?
Code:
(!(b1 & 0x80) )

b1 is int datatype.

variable "pHead" is "final String pHead;"

Thanks
S
 
Old 01-08-2008, 07:14 AM   #2
scoban
Member
 
Registered: Nov 2004
Location: Turkey
Distribution: Slackware
Posts: 145

Rep: Reputation: 16
~ is the java bitwise NOT operator.
How you initialize pHead, try pHead = new String ("xxx");
 
Old 01-08-2008, 07:19 AM   #3
sharathkv
Member
 
Registered: Jul 2003
Distribution: HP-UX
Posts: 35

Original Poster
Rep: Reputation: 15
~(tilde) is not working.
Code:
FirmwareTest.java:52: operator || cannot be applied to boolean,int
                if ((len != 270) || (s0.charAt(0) != 0x83) || (~(b1 & 0x80) ) ) {
Any ideas?

Thanks
S
 
Old 01-08-2008, 09:43 AM   #4
scoban
Member
 
Registered: Nov 2004
Location: Turkey
Distribution: Slackware
Posts: 145

Rep: Reputation: 16
No It is working, look error message carefully. What is the value of b1? What are you trying to achieve by ~(b1 & 0x80) Java is expecting a boolean you are giving it an int...
 
Old 01-08-2008, 04:57 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
(!(b1 & 0x80) ) translates to ((b1 & 0x80) != 0)

substring not subString
 
Old 01-09-2008, 09:05 AM   #6
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Tip:
Unless this is an exercise to learn java (or another number of reasons :} )swig could have saved you time by writing wrappers and calling into your Cpp code.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
convert milliseconds to formatted data in JAVA xface66 Programming 1 12-17-2007 10:05 AM
Java - Convert String to Date and back Kamikazee Programming 1 04-27-2006 02:52 AM
Convert Java to C++? leanieleanz Programming 6 03-04-2005 12:14 PM
can't convert o to FLoat in Java alaios Programming 4 04-24-2004 02:10 PM
How to convert a Java Program into.... anoop_chandran Programming 18 12-03-2001 05:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration