bugGNU Octave - Bugs: bug #36458, Bitset error

 
 

bug #36458: Bitset error

Submitter:  Fu Juay Chang <richerard>
Submitted:  Sun 13 May 2012 12:09:07 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.6.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 14 May 2012 04:48:22 AM UTC, comment #3: 

The following patch fixes the bug for me:

http://hg.savannah.gnu.org/hgweb/octave/rev/056ea51070b8

Closing this report. If there are outstanding problems, please reopen this.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Sun 13 May 2012 03:39:24 PM UTC, comment #2: 

Matlab (R2009B) says:

>> a=uint8([1,2;3 4])


a =

    1    2
    3    4

>> bitset(a,1,[0 1; 0 1])


ans =

    0    3
    2    5

and:

>> help bitset

 BITSET Set bit.
    C = BITSET(A,BIT) sets bit position BIT in A to 1 (on). A must be an
    unsigned integer or an array of unsigned integers, and BIT must be a
    number between 1 and the length in bits of the unsigned integer class
    of A, e.g., 32 for UINT32s.
 
    C = BITSET(A,BIT,V) sets the bit at position BIT to the value V.
    V must be either 0 or 1.
 
    Example:
       Repeatedly subtract powers of 2 from the largest UINT32 value:
 
       a = intmax('uint32')
       for i = 1:32, a = bitset(a,32-i+1,0), end
 
    See also BITGET, BITAND, BITOR, BITXOR, BITCMP, BITSHIFT, INTMAX.

So, it is a little unclear what if anything should be
done about this.  Possibly check for valid third argument?

In any case, what was the motivation for a vector third
argument which Matlab does not officially support?

Michael Godfrey <godfrey>
Group Member
Sun 13 May 2012 03:01:53 PM UTC, comment #1: 

The third argument is expected to be a scalar.  From 'help bitset':

VAL = 0 resets and VAL = 1 sets the bits.

You can do something like this instead:


> [bitset(a(:,1), 1, 0), bitset(a(:,2), 1, 1)]
ans =

  0  3
  2  5


This is working correctly as it is documented.  I don't think this is Matlab behavior either.  Are you requesting this as a new feature?

Mike Miller <mtmiller>
Group Member
Sun 13 May 2012 12:09:07 PM UTC, original submission:  


>> a=uint8([1, 2;3 4])

a =

  1  2
  3  4

>> bitset(a, 1, [0 1; 0 1])

ans =

  0  2
  2  4

----------------------------------------
The result is incorrect. It should be

ans =
  0 3
  2 5

Fu Juay Chang <richerard>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jordigh (Updated the item)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by richerard (Submitted the item)
  • -email is unavailable- added by richerard
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-05-14 jordigh StatusNeed Info Fixed
        Open/ClosedOpen Closed
        Operating SystemMicrosoft Windows Any
    2012-05-13 jordigh SummaryBitset error! Bitset error
    2012-05-13 mtmiller StatusNone Need Info
    2012-05-13 richerard Carbon-Copy- Added richerard

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code