Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default bitwise functions

I need bitwise functions for a spreadsheet (shift, OR, XOR, etc). Is there a
way to do this in Excel for example?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default bitwise functions

Excel has an OR function and VBA has both OR and XOR but the latter is not
included as a worksheet function but for XOR you can use.

=NOT(A1)+NOT(B1)=1

another XOR

=(A1<0)+(B1<0)=1

I have no idea what 'shift' or etc mean in this context
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"vbano" wrote:

I need bitwise functions for a spreadsheet (shift, OR, XOR, etc). Is there a
way to do this in Excel for example?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 905
Default bitwise functions

"Mike H" wrote:
Excel has an OR function and [...] for XOR you can use.
=NOT(A1)+NOT(B1)=1


Excel functions are boolean operations, not bitwise operations. Compare the
difference between:

=--AND(12,10)

=bitAND(12,10)

Function bitAND(a as long, b as long) as long
bitAND = a AND b
End Function

Presumably, the OP wants the bitAND result.

For Mike's edification, the difference is: a bitwise function operates on
the individual truth value (0 or 1) of individual bits, whereas a boolean
function operates on the truth value (zero or non-zero) of the entire value.

binAND(12,10) is 8 because 12 is the binary 1100, 10 is the binary 1010, and
8 is the binary 1000.


I have no idea what 'shift' or etc mean in this context


Ostensibly, shift left and right can be accomplish by multiplying and
dividing by 2, assuming the OP does not want circular shifts.

However, that will not shift bits into and out the sign bit. I believe that
handling that will also cover the boundary condition the can result in an
overflow error when "shifting left".


----- original message -----

"Mike H" wrote:
Excel has an OR function and VBA has both OR and XOR but the latter is not
included as a worksheet function but for XOR you can use.

=NOT(A1)+NOT(B1)=1

another XOR

=(A1<0)+(B1<0)=1

I have no idea what 'shift' or etc mean in this context
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"vbano" wrote:

I need bitwise functions for a spreadsheet (shift, OR, XOR, etc). Is there a
way to do this in Excel for example?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 905
Default bitwise functions

I wrote:
Ostensibly, shift left and right can be accomplish by multiplying and
dividing by 2, assuming the OP does not want circular shifts.

However, that will not shift bits into and out the sign bit. I believe
that
handling that will also cover the boundary condition the can result in an
overflow error when "shifting left".


I presume that the OP is only interested in bitwise operations for (up to)
32-bit integers -- type Long in VBA. But of course, Excel will store the
result effectively as type Double.

Ostensibly, that is not a problem since type Double has a 52-bit mantissa
and a separate sign bit. But ironically, if the left shift is done in Excel
(multiply by 2), there is no overflow problem.


binAND(12,10) is 8 because 12 is the binary 1100, 10 is the binary 1010,
and 8 is the binary 1000.


Of course, the type Double representation looks very different. But that
does not matter because no precision is lost when converting from 32-bit
integer (Long) to Double, then to 32-bit integer again.


----- original message -----

"Joe User" <joeu2004 wrote in message
...
"Mike H" wrote:
Excel has an OR function and [...] for XOR you can use.
=NOT(A1)+NOT(B1)=1


Excel functions are boolean operations, not bitwise operations. Compare
the
difference between:

=--AND(12,10)

=bitAND(12,10)

Function bitAND(a as long, b as long) as long
bitAND = a AND b
End Function

Presumably, the OP wants the bitAND result.

For Mike's edification, the difference is: a bitwise function operates on
the individual truth value (0 or 1) of individual bits, whereas a boolean
function operates on the truth value (zero or non-zero) of the entire
value.

binAND(12,10) is 8 because 12 is the binary 1100, 10 is the binary 1010,
and
8 is the binary 1000.


I have no idea what 'shift' or etc mean in this context


Ostensibly, shift left and right can be accomplish by multiplying and
dividing by 2, assuming the OP does not want circular shifts.

However, that will not shift bits into and out the sign bit. I believe
that
handling that will also cover the boundary condition the can result in an
overflow error when "shifting left".


----- original message -----

"Mike H" wrote:
Excel has an OR function and VBA has both OR and XOR but the latter is
not
included as a worksheet function but for XOR you can use.

=NOT(A1)+NOT(B1)=1

another XOR

=(A1<0)+(B1<0)=1

I have no idea what 'shift' or etc mean in this context
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"vbano" wrote:

I need bitwise functions for a spreadsheet (shift, OR, XOR, etc). Is
there a
way to do this in Excel for example?


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
bitwise operations as in xor stevenshrii Excel Discussion (Misc queries) 2 April 16th 09 09:43 AM
how to do "bitwise and operation" in excel? Parth Excel Worksheet Functions 0 May 3rd 07 08:30 PM
How do I perform bitwise logical anding and oring in Excel? Mitchell Heldt Excel Worksheet Functions 0 August 6th 06 08:50 PM
efficiency: database functions vs. math functions vs. array formula nickname Excel Discussion (Misc queries) 2 July 14th 06 04:26 AM
Where are Bitwise Operators Dennis W. Bulgrien Excel Worksheet Functions 1 June 30th 06 05:51 PM


All times are GMT +1. The time now is 04:28 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"