Re: Bitwise operators
- From: den2k <den2k88@xxxxxxxxx>
- Date: Thu, 19 Jun 2008 03:37:04 -0700 (PDT)
On 19 Giu, 11:32, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
den2k said:
Given subtraction, division becomes not only possible but even easy.Consider 34 / 10 (which we need to do if we're going to get the result 3
and remainder 4). 34 is 100010 in binary, and ten is 1010. Observe long
division in binary, noting that subtraction is done with ^ & << and the
two's complement, comparison can be done by subtraction, isolating the
bits necessary for the trial divisions can be done using shift and AND,
and "bringing down a bit" can be done with shift and OR:
1010)100010
1010 <---- Subtrahend <= minuend? No.
_0000
1010)100010
1010 <---- Subtrahend <= minuend? Yes. Subtract.
_00001
1010)100010
1010
---
111 <----- bring down a bit
_00001
1010)100010
1010
---
1110
1010 <---- Subtrahend <= minuend? Yes. Subtract.
_000011 <---- Result: 3
1010)100010
1010
---
1110
1010
---
100 <---- Remainder: 4
Yes, Virginia, you *can* divide by ten, even if you're thinking in binary.
Whoops I unconsciously thougt to a sigle bitwise operator.. and I
didn't know so well the use of bitwise Operators in order to do the
basilar operations. Thanks a lot.
.
- References:
- Bitwise operators
- From: Santhosh
- Re: Bitwise operators
- From: rahul
- Re: Bitwise operators
- From: den2k
- Re: Bitwise operators
- From: Richard Heathfield
- Bitwise operators
- Prev by Date: CD DVD Recovery Toolbox Free
- Next by Date: Re: Do memory allocations need to be freeed every time?
- Previous by thread: Re: Bitwise operators
- Next by thread: Do memory allocations need to be freeed every time?
- Index(es):
Relevant Pages
|