Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Binary Operations

Reply
Thread Tools

Binary Operations

 
 
MarcoGT
Guest
Posts: n/a
 
      02-27-2004
Hi,

i had to do some mathematical operations with binary numbers...; but i see
tha this is not implmented in Java; where can i find something for example?

Thanks.

Bye


 
Reply With Quote
 
 
 
 
Collin VanDyck
Guest
Posts: n/a
 
      02-27-2004
"MarcoGT" <(E-Mail Removed)> wrote in message
news:c1odij$1m04i7$(E-Mail Removed)-berlin.de...
> Hi,
>
> i had to do some mathematical operations with binary numbers...; but i see
> tha this is not implmented in Java; where can i find something for

example?
>
> Thanks.
>
> Bye
>
>


You can certainly do binary operations.

You have the standard bitwise AND (&) and the bitwise OR (|) that you would
have in other languages. Also, the Integer class let's you take any int and
give you the binary string representation:

int x = 7;
Integer.toBinaryString(x); // this returns "111"

So what exactly is it you are trying to do? Please try and give more
information.

-CV


 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      02-27-2004
MarcoGT wrote:
> i had to do some mathematical operations with binary numbers...; but i see
> tha this is not implmented in Java;


What "mathematical operations" are you talking about? Java definitely has all
the usual mathematical operations (+, -, *, /), which have nothing to do with
the numbers' base (which is a property of their representation, not the
numbers itself). It also internally uses a binary format and offers
appropriate bitwise operations (AND, OR, etc.) and finally you can easily
convert between numerical variables and a binary String reprentations.

So what exactly do you want to do and why do you believe it's not implemented
in Java?

 
Reply With Quote
 
MarcoGT
Guest
Posts: n/a
 
      02-28-2004

"Collin VanDyck" <(E-Mail Removed)> ha scritto nel messaggio
news:W3P%b.9372043$(E-Mail Removed)...
> "MarcoGT" <(E-Mail Removed)> wrote in message
> news:c1odij$1m04i7$(E-Mail Removed)-berlin.de...
> So what exactly is it you are trying to do? Please try and give more
> information.


I need to do sums ed subractions;

for example i tried to make 111+1 and the result was 112...why?

Thanks


 
Reply With Quote
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      02-28-2004
MarcoGT wrote:

>
> "Collin VanDyck" <(E-Mail Removed)> ha scritto nel messaggio
> news:W3P%b.9372043$(E-Mail Removed)...
>> "MarcoGT" <(E-Mail Removed)> wrote in message
>> news:c1odij$1m04i7$(E-Mail Removed)-berlin.de...
>> So what exactly is it you are trying to do? Please try and give more
>> information.

>
> I need to do sums ed subractions;
>
> for example i tried to make 111+1 and the result was 112...why?
>
> Thanks


Because 111 + 1 is 112 ofcourse

Seriously, all math in java is base 10 by default.

What you can do is retrieve your base 2 numbers in String form, convert them
to an int using Integer.parseInt("111",2), and add those ints. To get the
resulting base 2 representation, use Integer.toBinaryString on the sum, as
someone has mentioned before.


--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
polymorphism and binary operations on objects Leslaw Bieniasz C++ 4 09-22-2004 11:05 PM
Binary File Operations Jeremy Robbins Perl 0 07-14-2004 09:45 PM
Re: ostreams, ios::binary, endian, mixed binary-ascii Marc Schellens C++ 8 07-15-2003 12:27 PM



Advertisments