Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I do AND operation on two binary numbers in MS Excel?

I want to do AND say to the following:
00101001
AND to
10001001

and should get the following answer:

00001001

What function should I use in MS Excel to get this?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How can I do AND operation on two binary numbers in MS Excel?

All you need to do is to put the zeros and ones in separate cells. Then the
AND function will work:

=--AND(A1,A2)
--
Gary's Student


"Zuke" wrote:

I want to do AND say to the following:
00101001
AND to
10001001

and should get the following answer:

00001001

What function should I use in MS Excel to get this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default How can I do AND operation on two binary numbers in MS Excel?

Not sure what operation you want to do with these numbers. Converted to
decimal you have asked that
41 AND 137 = 9
If you go to Tools/Add-ins and check Analysis ToolPak, you will get some
additional math functions that work with Binary, Octal and Hexadecimal
numbers.
Mike F

"Zuke" wrote in message
...
I want to do AND say to the following:
00101001
AND to
10001001

and should get the following answer:

00001001

What function should I use in MS Excel to get this?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default How can I do AND operation on two binary numbers in MS Excel?

On Wed, 11 Jan 2006 14:50:02 -0800, "Zuke"
wrote:

I want to do AND say to the following:
00101001
AND to
10001001

and should get the following answer:

00001001

What function should I use in MS Excel to get this?



I don't know how to do it with a worksheet function. But you can write a UDF
(user-defined function) in VBA to do that.

<alt-F11 opens the VB Editor.

Ensure your project is highlighted in the Project Explorer window. Then
Insert/Module and paste the code below into the window that opens.

You can use the function by typing:

=BinaryAND(00101001,00001001)

or by placing those numbers into cells, and using the cell references.

The AND function in VBA is supposed to do something similar, but I cannot seem
to get it to work properly at this time.

================================
Option Explicit
Function BinaryAND(n1, n2) As String
Dim i As Long
Dim l As Long
Dim b1 As String, b2 As String
Dim Fmt As String
Dim temp As String

l = Application.WorksheetFunction.Max(Len(n1), Len(n2))

Fmt = Application.WorksheetFunction.Rept("0", l)

b1 = Format(n1, Fmt)
b2 = Format(n2, Fmt)

For i = 1 To l
temp = temp & Mid(b1, i, 1) * Mid(b2, i, 1)
Next i

BinaryAND = temp

End Function
===================================


--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How can I do AND operation on two binary numbers in MS Excel?

Zuke,
Not a complete solution yet, but the ArrayFormula "{=F11+F12}" returns
10102002, so with a couple of SUBSTITUTEs you get the answer.
There probably a better way !

NickHK

"Zuke" wrote in message
...
I want to do AND say to the following:
00101001
AND to
10001001

and should get the following answer:

00001001

What function should I use in MS Excel to get this?







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How can I do AND operation on two binary numbers in MS Excel?

Reading this again, am I stupid, or does this work ?
(Although a simple addition suffices)

NickHK

"NickHK" wrote in message
...
Zuke,
Not a complete solution yet, but the ArrayFormula "{=F11+F12}" returns
10102002, so with a couple of SUBSTITUTEs you get the answer.
There probably a better way !

NickHK

"Zuke" wrote in message
...
I want to do AND say to the following:
00101001
AND to
10001001

and should get the following answer:

00001001

What function should I use in MS Excel to get this?







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default How can I do AND operation on two binary numbers in MS Excel?

If you set a vba library reference to "atpvbaen.xls", then the following
returns the string "1001"

Sub Demo()
Dim s1, s2, Answer
s1 = "00101001"
s2 = "10001001"

' Returns 1001
Answer = Dec2Bin(Bin2Dec(s1) And Bin2Dec(s2))
End Sub

HTH
--
Dana DeLouis
Win XP & Office 2003


"Zuke" wrote in message
...
I want to do AND say to the following:
00101001
AND to
10001001

and should get the following answer:

00001001

What function should I use in MS Excel to get this?



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default How can I do AND operation on two binary numbers in MS Excel?

should get the following answer: 00001001

Oops. For leading zero's, a slight change...

Sub Demo()
Dim s1, s2, Answer
s1 = "00101001"
s2 = "10001001"

' Returns 00001001
Answer = Dec2Bin(Bin2Dec(s1) And Bin2Dec(s2), 8)
End Sub

--
Dana DeLouis
Win XP & Office 2003

<snip


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary Numbers Sanford Lefkowitz Excel Discussion (Misc queries) 9 May 12th 10 04:06 PM
EXCEL: How to present 8-bits binary numbers HK Excel Discussion (Misc queries) 2 February 2nd 09 06:19 PM
large binary numbers Himu Excel Worksheet Functions 4 July 27th 05 02:53 AM
Binary numbers longer than 10 characters Andibevan[_3_] Excel Programming 4 April 11th 05 12:21 PM
Binary Numbers longer than 10 characters Andibevan Excel Worksheet Functions 2 April 6th 05 10:08 PM


All times are GMT +1. The time now is 04:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"