How to resolve the algorithm Bitwise operations step by step in the QB64 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Bitwise operations step by step in the QB64 programming language

Table of Contents

Problem Statement

Write a routine to perform a bitwise AND, OR, and XOR on two integers, a bitwise NOT on the first integer, a left shift, right shift, right arithmetic shift, left rotate, and right rotate. All shifts and rotates should be done on the first integer with a shift/rotate amount of the second integer. If any operation is not available in your language, note it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Bitwise operations step by step in the QB64 programming language

Source code in the qb64 programming language

' no rotations and shift aritmetic are available in QB64
' Bitwise operator in Qbasic and QB64
'AND (operator) the bit is set when both bits are set.
'EQV (operator) the bit is set when both are set or both are not set.
'IMP (operator) the bit is set when both are set or both are unset or the second condition bit is set.
'OR (operator) the bit is set when either bit is set.
'NOT (operator) the bit is set when a bit is not set and not set when a bit is set.
'XOR (operator) the bit is set when just one of the bits are set.
Print "Qbasic and QB64 operators"
Print " Operator        1 vs 1   1 vs 0   0 vs 0"

Print "AND", 1 And 1, 1 And 0, 0 And 0
Print " OR", 1 Or 1, 1 Or 0, 0 Or 0
Print "XOR", 1 Xor 1, 1 Xor 0, 0 Xor 0
Print "EQV", 1 Eqv 1, 1 Eqv 0, 0 Eqv 0
Print "IMP", 1 Imp 1, 1 Imp 0, 0 Imp 0
Print "NOT", Not 1, Not 0, Not -1, Not -2

Print "QB64 operators"
Dim As _Byte a, b, c
a = 1: b = 1: c = 1
For i = 1 To 4
    Print a, b, c
    Print _SHL(a, i), _SHL(b, i * 2), _SHL(c, i * 3)
Next
a = 16: b = 32: c = 8
For i = 1 To 4
    Print a, b, c
    Print _SHR(a, i), _SHR(b, i * 2), _SHR(c, i * 3)
Next

  

You may also check:How to resolve the algorithm User input/Text step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Biorhythms step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm 24 game step by step in the PL/I programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the jq programming language
You may also check:How to resolve the algorithm Execute Brain step by step in the Modula-3 programming language