Skip to content

Numerous misuse of bitwise & #23

@JohnWTMurray

Description

@JohnWTMurray

if ((lastActiveWord != null) & (activeWord==null)) {

This is one of multiple instances of the 'bitwise and' operator being used where the 'logical and' operator should have been used.

bitwise AND: &
logical AND: &&

Logical AND (&&) takes the expression before it and the expression after it (both expressions should be booleans), combining to a larger expression that evaluates to a boolean. This boolean is true if both expressions fed to it are true. Since the two expressions fed to it use comparative operators (==, !=) they evaluate to booleans.

Bitwise AND is not evaluating the total expression to a boolean, but a number that happens to be truthy, so the code is working for the wrong reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions