Menu

portb.2 = ! portb.2

Help
JB
2024-03-12
2024-03-13
  • JB

    JB - 2024-03-12

    Hi everyone,
    this is just a very simple question,
    my main compiler is PBP3 Pro, and I'm use to this operator condition (<> or !=Not Equal)
    but in GCStudio it's read as "=!"

    is this the same.

    thank's to everyone.

     
  • Anobium

    Anobium - 2024-03-13

    The difference between the comparison operator (<>) and the bitwise NOT operator (!):


    Comparison Operator (<>)


    * Used to compare two values.
    * Common examples: aa < bb, xx <> yy, zz >= 10.
    * Results in a boolean value (true or false) indicating whether the comparison holds.
    * Works with various numeric data types.
    * GCBASIC uses <> for comparison, != is not supported.


    Bitwise NOT Operator (!)


    * Used to perform a bitwise inversion on a single value.
    * Flips each bit (0 becomes 1, 1 becomes 0) of the binary representation of the value.
    * Results in a new value with inverted bits.
    * Primarily used for manipulating binary data at the bit level.


    Key Differences:


    Purpose: Compare vs. Invert bits.
    Operands: Takes two values for comparison vs. one value for bitwise inversion.
    Result: Boolean (true/false) vs. New value with inverted bits.
    Data Type: Can work with various data types vs. Primarily for binary data.


    In Summary:


    <> checks the relationship between two values.
    ! flips the bits of a single value.


    They serve entirely different purposes in programming.

     

    Last edit: Anobium 2024-03-13
  • Anobium

    Anobium - 2024-03-13

    I'm use to this operator condition (<> or !=Not Equal)
    but in GCStudio it's read as "=!"

    Take a real example.

    aa = 55 and bb = 160

    aa <> bb equates to 55 <> 160 therefore true
    aa =! bb equates to 55 = 95 there false

    Hold on... 95... why? 160 = 0b10100000 and if you NOT this binary value you get 0b1011111... which is 95.

    So, <> is a comparison and GBASIC does not support != ( as an equivalent ), and, =! is a NOT operator.

     
  • JB

    JB - 2024-03-13

    Now it's clear
    Thank's Anobium

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.