BigInt icon indicating copy to clipboard operation
BigInt copied to clipboard

Support bitwise operation

Open yyyoungha opened this issue 5 years ago • 12 comments

Why don't we add bitwise operators here?

Features for bitwise operation

1. bitwise opeartors

  • bitwise OR ( | )
  • bitwise AND ( & )
  • bitwise XOR ( ^ )
  • bitwise NOT ( ~ )
  • bitwise LEFT SHIFT ( << )
  • bitwise RIGHT SHIFT ( >> )

2. bitwise-assignment opeartors

  • bitwise-assignment OR ( |= )
  • bitwise-assignment AND ( &= )
  • bitwise-assignment XOR ( ^= )
  • bitwise-assignment LEFT SHIFT ( <<= )
  • bitwise-assignment RIGHT SHIFT ( >>= )

yyyoungha avatar Sep 12 '20 16:09 yyyoungha

Sure! It would be nice to have bitwise operators.

faheel avatar Oct 05 '20 18:10 faheel

I'd be interested in working on working on this issue. This would be my first contribution to an open-sourced project, so I'm not sure if there's a formal way to get assigned to it (the contribution guidelines seemed like just to leaving a note in the issue was enough), but I didn't see anyone else assigned to it so I thought I'd throw my hat in the ring.

muytingc avatar Nov 05 '20 19:11 muytingc

@muytingc Sure, you can work on it! There's no need to be assigned to an issue - if you don't find an open pull request (PR) for an issue then you can submit a PR with your code (the PR doesn't even need to have all of the functionality in the beginning). Then in the PR comments and code review you can clear your doubts, if any, and we can iron out the finer details of the implementation.

faheel avatar Nov 06 '20 10:11 faheel

Hi @faheel, first-time contributor here. I have implemented the left-shift and right-shift operations so far. Can I open a pull request for them or will it conflict with @muytingc's work?

harish-vnkt avatar Nov 17 '20 23:11 harish-vnkt

@harish-vnkt Since there's no PR currently for this issue you can feel free to create one.

faheel avatar Nov 20 '20 01:11 faheel

@faheel When implementing bitwise NOT, would it be more useful to assume that the binary representation of the BigInt stops at the highest 1 bit, or add additional 0 bits up to the nearest power of 2?

arenbecl avatar Dec 06 '20 22:12 arenbecl

Can I make my first contribution in bitwise. I am new to open source!!

Priyanshi-Chauhan avatar Aug 25 '21 17:08 Priyanshi-Chauhan

Is the issue still relevant ? @faheel

aniketh-varma avatar Aug 28 '21 11:08 aniketh-varma

we need bitwise operations

cristian-5 avatar Dec 07 '22 16:12 cristian-5

Sorry for the late reply. #63 is a high-quality PR by @arenbecl that adds almost all bitwise operators, but is missing test cases. If anyone is interested in contributing they can add test cases by creating a fork of https://github.com/arenbecl/BigInt/tree/bitwise-assignment-operators and sending another PR.

faheel avatar Dec 18 '22 09:12 faheel

Hi, @faheel I created a PR with the tests for this issue. There is something which must be discussed, though, please see the comments in the PR.

GNL10 avatar Feb 08 '23 00:02 GNL10

I recommend using the gmp library as it is more mature.

ZuoFuhong avatar Jul 17 '23 08:07 ZuoFuhong