Reply to topic  [ 3 posts ] 
Bitwise conversions 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
If I have a bit mask (i.e. a decimal conversion of a binary number) and I want to find the ...

Ah, I think I've got it :D Thanks!

:lol:

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Apr 03, 2012 10:34 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
OK, got a question now :D

It is bitwise operator related but be thinking about sudoku to put it in context.

I will be comparing three cells.

Cell a will have the definite number 7 in it (for example).
Cell b will have the definite number 5 in it.
Cell c will have the candidate numbers 1, 3, 5 and 7 in it.
They can all "see" each other (i.e. in the same box, row or column).

At the moment my loop runs and I end up so that...

Cell a = 7
Cell b = 5
Cell c = 1,3 (i.e. it has had 5 and 7 eliminated)

BTW (7 is actually 64 and 1,3 is actually 5 (bitwise)).

That's all very good and VERY quick but at the end I want to see what has been removed.

If I take a copy at the beginning so I have ...

origCell a = 7
origCell b = 5
origCell c = 1,3,5,7

How can I compare cell c and origCell c to see what has been eliminated?

cell c = 1,3 = 5 = 000000101
origCell c = 1,3,5,7 = 85 = 001010101

Ah, XOR! cell c XOR origCell c = 001010000 = 80

Is that right?

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Wed Apr 04, 2012 1:58 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Ah, I can then get the individual bits using a shift operator.
Code:
int dif = the xor that gives me the numbers that have been removed.

    for(int i = 1; i <= 9; i++)
    {
        int bit = dif & 1;

        if (bit == 1)
            cout << "elim " << i << endl;

        dif = dif >> 1;
    }


This lists all the numbers (bits) that were eliminated from the given cell.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Wed Apr 04, 2012 2:15 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.