Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Add Method
hi, i need help with this method please. if anyone can help, i will
apreciated. A method called getUnsignedValue.  This method should
calculate and return the decimal number equivalent to the binary number
stored in the object.  This method should simply return the integer
equivalent of the Binary number object.  The calculation is performed
assuming that the binary number object is in standard binary notation,
and therefore does not have negative values.  Note: this method should
NOT change the data stored inside the object!


Report this thread to moderator Post Follow-up to this message
Old Post
shiv
09-23-06 12:03 AM


Re: Add Method
shiv wrote:
> hi, i need help with this method please.

What do you have so far (besides a problem description)?

Andrew T.


Report this thread to moderator Post Follow-up to this message
Old Post
Andrew Thompson
09-23-06 12:03 AM


Re: Add Method
"shiv" <rajeev0628@gmail.com> wrote in message
news:1158955827.535227.123710@m73g2000cwd.googlegroups.com...
> hi, i need help with this method please. if anyone can help, i will
> apreciated. A method called getUnsignedValue.  This method should
> calculate and return the decimal number equivalent to the binary number
> stored in the object.  This method should simply return the integer
> equivalent of the Binary number object.  The calculation is performed
> assuming that the binary number object is in standard binary notation,
> and therefore does not have negative values.  Note: this method should
> NOT change the data stored inside the object!

It's not entirely clear what you're asking.  All data in the computer are in
binary, so is your object simply an Integer or even an int?  What do you
mean by decimal equivalent?  Do you mean to convert the number to a string?
"Standard" binary notation (2's complement in my world) includes negative
numbers, so you are saying this binary number is already unsigned?  And
Integers are already immutable.

My guess is that this is an exercise for a 1st-year computer science course
and it means to convert positive number (probably in an int) into a String
for display--a very common type of exercise.

You'll have to explain more about what you're trying to do.

Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
>



Report this thread to moderator Post Follow-up to this message
Old Post
Matt Humphrey
09-25-06 12:03 AM


Re: Add Method
"shiv" <rajeev0628@gmail.com> wrote in message
news:1158955827.535227.123710@m73g2000cwd.googlegroups.com...
> hi, i need help with this method please. if anyone can help, i will
> apreciated. A method called getUnsignedValue.  This method should
> calculate and return the decimal number equivalent to the binary number
> stored in the object.  This method should simply return the integer
> equivalent of the Binary number object.  The calculation is performed
> assuming that the binary number object is in standard binary notation,
> and therefore does not have negative values.  Note: this method should
> NOT change the data stored inside the object!
>

This will do what you want

/**
* returned the unsigned value as an int
*/
public int getUnsigned( byte b)
{
int result = 0;
if ((b & 0x80) != 0)
{
result = (int) 0x80;
}
else
result = 0;
result += (0x7f & b);
return result;
}



Report this thread to moderator Post Follow-up to this message
Old Post
Joan C
09-30-06 09:01 AM


Re: Add Method
Joan C wrote:
> "shiv" <rajeev0628@gmail.com> wrote in message
> news:1158955827.535227.123710@m73g2000cwd.googlegroups.com... 
>
> This will do what you want
>
> /**
> * returned the unsigned value as an int
> */
> public int getUnsigned( byte b)
> {
>  int result = 0;
>   if ((b & 0x80) != 0)
>  {
>   result = (int) 0x80;
>  }
>  else
>   result = 0;
>  result += (0x7f & b);
>  return result;
> }
>
>
Looks like someone had their homework assignment done for them..?

--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us
 ________________________________________
__________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

Report this thread to moderator Post Follow-up to this message
Old Post
IchBin
10-01-06 12:04 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:16 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.