From help-octave-request at bevo dot che dot wisc dot edu Wed Dec 12 09:57:34 2001 Subject: Re: logical and ???? From: Paul Kienzle To: "John W. Eaton" , Matthew Flax Cc: help-octave at bevo dot che dot wisc dot edu Date: Wed, 12 Dec 2001 10:55:20 -0500 Thanks to Kai Habel, we have bitand, bitor, etc. as oct-files in octave-forge at http://octave.sf.net but limited to 32 bits. I can replace all of the bit functions with m-file implementations using arithmetic (+,-,*,/) except for bitand. If I can figure out bitand, then we can use all the bits of the mantissa for a double (which is 53 bits I believe). Any suggestions? bitxor(a,b) : (a - bitand(a,b)) + (b - bitand(a,b)) bitor(a,b) : (a - bitand(a,b)) + b bitset(a,n) : a + sum(2.^n) bitset(a,n,0) : a - bitand(a,sum(2.^n)) bitget(a,n) : bitand(a,2^n) != 0 bitshift(a,k) : fix (a * 2^k) bitcmp(a) : (2.^bitmax - 1) - a Paul Kienzle pkienzle at users dot sf dot net On Tue, Dec 11, 2001 at 10:40:05PM -0600, John W. Eaton wrote: > On 12-Dec-2001, Matthew Flax wrote: > > | When I try the following I get a confusing answer : > | > | octave:47> 0x4 & 0x8 > | ans = 1 > | > | surely that should be ans=0 ? > > No. The & and | operators work element-by-element for matrices. Your > 0x4 and 0x8 numbers are just scalars, so the result is 1, which tells > you that both elements in the comparison are nonzero. If you want > bit-wise operations, you need some functions to do it. The matcompat > package may have some, but they aren't distributed as a part of Octave > (yet). > > jwe > > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------