Facebook Page
Twitter
RSS
+ Reply to Thread
Results 1 to 6 of 6
  1. MHB Master
    MHB Site Helper
    mathmari's Avatar
    Status
    Offline
    Join Date
    Apr 2013
    Posts
    2,588
    Thanks
    2,073 times
    Thanked
    663 times
    Trophies
    1 Highscore
    Awards
    MHB Chat Room Award (2015)  

MHB Model User Award (2015)  

MHB LaTeX Award (2015)
    #1
    Hey!!

    I want to check using bitwise operations if x XOR y=0.

    The only conditional command we have is JMN a, which means Jump to a if the currect value is <0.

    So, we have to check if it doesn't hold that x XOR y <0 and x XOR y >0, right?

    But how can we check the condition x XOR y >0 ?

    Using the operation NOT ( x XOR y ) we don't get -(x XOR y) right?

  2. MHB Master
    MHB Site Helper
    MHB Math Scholar

    Status
    Offline
    Join Date
    Jan 2012
    Posts
    2,192
    Thanks
    510 times
    Thanked
    4,078 times
    Thank/Post
    1.860
    Awards
    MHB Chat Room Award (2016)  

MHB Humor Award (2016)  

MHB Discrete Mathematics Award (2016)  

MHB Best Ideas Award (2015)  

MHB Discrete Mathematics Award (2015)
    #2
    Quote Originally Posted by mathmari View Post
    I want to check using bitwise operations if x XOR y=0.
    What do you mean by checking? What are x and y?

    Quote Originally Posted by mathmari View Post
    The only conditional command we have is JMN a, which means Jump to a if the currect value is <0.
    And literally no single other command?

  3. MHB Craftsman

    Status
    Offline
    Join Date
    Mar 2016
    Location
    Melbourne Australia
    Posts
    104
    Thanks
    187 times
    Thanked
    193 times
    Trophies
    1 Highscore
    #3
    Quote Originally Posted by mathmari View Post

    Using the operation NOT ( x XOR y ) we don't get -(x XOR y) right?
    -(x XOR y) ? Do you mean $\lnot(x \ XOR \ y)$ ?

    x XOR y will be 0 when either x or y is 1 but not both. You can see a truth table for this.

    Evgeny makes a good point by asking what x and y are. Unless you are using some sort of thresholding operation, typically bitwise operations will have solutions of either true or false, 1 or 0, not 'greater than 0' or 'less than 0'.

    Maybe you want to use some other variables to test the x XOR y condition, and then assign something to a data type that can handle the '> 0' part?

  4. MHB Master
    MHB Site Helper
    mathmari's Avatar
    Status
    Offline
    Join Date
    Apr 2013
    Posts
    2,588
    Thanks
    2,073 times
    Thanked
    663 times
    Trophies
    1 Highscore
    Awards
    MHB Chat Room Award (2015)  

MHB Model User Award (2015)  

MHB LaTeX Award (2015)
    #4 Thread Author
    Quote Originally Posted by Joppy View Post
    x XOR y will be 0 when either x or y is 1 but not both. You can see a truth table for this.
    XOR checks if each bit of the two values is the same, or not?
    I mean that if one bit is the same the result is 0, and if not the result is 1, right?

    For example, we have that
    1100 XOR 1010 = 0110
    . So, only if the result is 0 we have that the two numbers are the same, right?



    It holds that $x-y=0$ if it doesn't hold that $x-y<0$ and neither $x-y>0 \Rightarrow -(x-y)<0$.

    I implemented now the command NEG, that computes the negation of a constant.

    It holds that $x+ \sim x+1=0$. Therefore it holds that $-x= \sim x +1$.
    ($\sim x$ is the bitwise negation of $x$)



    So, for two constants $x$ and $y$, we want to check if $x \ XOR \ y=0$.

    1) We compute the
    x XOR y

    2) If the result is negative (JMN) then go to step 6
    3) We compute the negation of the above result
    4) If this is negative (JMN) then go to step 6
    5) It holds that $x \ XOR \ y=0$ and so $x=y$
    6) It holds that $x \ XOR \ y\neq 0$ and so $x\neq y$


    Is everything correct?

  5. MHB Craftsman

    Status
    Offline
    Join Date
    Mar 2016
    Location
    Melbourne Australia
    Posts
    104
    Thanks
    187 times
    Thanked
    193 times
    Trophies
    1 Highscore
    #5
    Quote Originally Posted by mathmari View Post
    XOR checks if each bit of the two values is the same, or not?

    I mean that if one bit is the same the result is 0, and if not the result is 1, right?
    It's just an operator. But i guess we can say it 'checks'. If two of the bits are the same, then the result is false. For all other cases, the result is true.


    Quote Quote:
    For example, we have that
    1100 XOR 1010 = 0110
    . So, only if the result is 0 we have that the two numbers are the same, right?
    Hmm. No? $1100 \ne 1010$ in base 10 and base 2. I see what you are trying to do though.. Can't we just,



    Or something along those lines


    I feel like you might be applying the rules and conditions of ordinary algebra to that of Boolean algebra. Changing the data type wherever it suits, so I don't really understand. I will leave it for someone more knowledgeable in the area to chime in .

  6. MHB Journeyman
    MHB Site Helper
    MHB Math Helper
    Rido12's Avatar
    Status
    Offline
    Join Date
    Jul 2013
    Posts
    692
    Thanks
    3,268 times
    Thanked
    782 times
    Thank/Post
    1.130
    Awards
    Chat Box Champion (2014)  

MHB Model User Award (2014)
    #6
    My two cents as someone who is pretty rusty in assembly language: I think the answer depends entirely on the instruction set of your assembly language, and depending on the commands thereof, there may be multiple ways of tackling this problem. Some assembly languages also have special registers that have particular functions which can simplify code.

    I think an important question to ask is which assembly language /processor you are using and which commands are available to you. The processor I used in the past had an operation XOR that would perform bitwise exclusive-or on two binary variables, and if resulted in 0, would toggle a certain bit on a register. All that was left to do was to check if that bit was set or not, and then branch from there. Sometimes you may be able to do this task directly if you have a "comparison" operator followed by a jump instruction.

    For example:

    CMP X, Y
    JMN LESSTHAN
    GREATERTHAN:
    ;do something
    LESSTHAN:
    ;do something

    If I recall correctly, the compare operator does perform some sort of subtraction, so the logic basically reduces to what Joppy has said. If you don't have a CMP operator, you may be able to use a SUB operator instead.

Similar Threads

  1. Number of operations
    By mathmari in forum Computer Science
    Replies: 3
    Last Post: June 27th, 2015, 08:10
  2. Bit Operations
    By HELPMEHELPME in forum Computer Science
    Replies: 4
    Last Post: April 26th, 2015, 14:53
  3. More Bitwise Arithmetic
    By tmt in forum Computer Science
    Replies: 2
    Last Post: December 8th, 2014, 10:53
  4. Bitwise arithmetic
    By tmt in forum Computer Science
    Replies: 4
    Last Post: December 7th, 2014, 15:13
  5. Order of Operations
    By Marvin Kalngan in forum Pre-Algebra and Algebra
    Replies: 1
    Last Post: April 19th, 2014, 21:48

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Math Help Boards