Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to add two binary numbers using bitwise AND

Reply
Thread Tools

How to add two binary numbers using bitwise AND

 
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      11-15-2007
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..
 
Reply With Quote
 
 
 
 
Joost Diepenmaat
Guest
Posts: n/a
 
      11-16-2007
On Thu, 15 Nov 2007 15:45:28 -0800, cyrusgreats wrote:

> 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.
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      11-16-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.
 
Reply With Quote
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      11-16-2007
On Nov 16, 8:47 am, (E-Mail Removed) wrote:
> (E-Mail Removed) wrote:
> > 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.


Thanks all for tips ..got it now. You guys are best
/Cheers
 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to add two numbers without using the plus operator? codergem@gmail.com C++ 17 12-17-2008 01:04 PM
(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
Add two numbers using a Single Variable! nirjhar.oberoi@gmail.com C Programming 4 07-22-2006 05:35 PM
how to multiply two integers using bitwise operators sandy_pt_in@yahoo.com C Programming 12 09-23-2003 05:04 PM



Advertisments