How to add two binary numbers using bitwise AND

C

cyrusgreats

I like to know how to add two binaary numbers using bitwise AND
something like that:
$bin_1 = 1011101000001
$bin_2 = 1000101010101
$result = 1000101000001

basically user enter two decimal numbers and code change those numbers
to binary then using bitwise prints the value/result the convert the
value to hex numbers.
Thanks in advance..
 
J

Joost Diepenmaat

I like to know how to add two binaary numbers using bitwise AND
something like that:
$bin_1 = 1011101000001
$bin_2 = 1000101010101
$result = 1000101000001

That's not addition.
basically user enter two decimal numbers and code change those numbers
to binary then using bitwise prints the value/result the convert the
value to hex numbers.
Thanks in advance..

Look up "bitwise and" in perlop.

Joost.
 
X

xhoster

I like to know how to add two binaary numbers using bitwise AND
something like that:
$bin_1 = 1011101000001
$bin_2 = 1000101010101
$result = 1000101000001

In addition to the other answers you got, you can do this as strings as
well:

print "1011101000001" & "1000101010101";

The good thing about this is that it is not limited to 32 or 64 bits.
The bad thing is that if the strings aren't the same length they will
be aligned in an unintuitive (for numbers) manner.

And or course the answer is a string rather than a number. Whether that is
good or bad depends on what you want.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
C

cyrusgreats

In addition to the other answers you got, you can do this as strings as
well:

print "1011101000001" & "1000101010101";

The good thing about this is that it is not limited to 32 or 64 bits.
The bad thing is that if the strings aren't the same length they will
be aligned in an unintuitive (for numbers) manner.

And or course the answer is a string rather than a number. Whether that is
good or bad depends on what you want.

Xho

--
--------------------http://NewsReader.Com/--------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Thanks all for tips ..got it now. You guys are best
/Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top