NOR
y = a NOR b
Bitwise NOT OR.
Truth table:
a | b | a NOR b |
---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 0 |
Example 1
The NOT-operation as part of NOR performs a bitwise inversion on all bits of a number. This leads to the following (maybe unexpected) result:
print 1 NOR 1 ' Output: 11111111111111111111111111111110
Example 2: Operate NOR only on last n bits
If you want to operate NOR only on the last n
bits of
the numbers, you can use the following code:
4
n = 0b1010
a = 0b1000
b =
print bin((a NOR b) BAND ((1 lshift n ) - 1))
' Output 101
Example 3: Set a bit
Def Bnot(n) = n Nor n ' Bnot inverts all bits in n (it's very useful for inverting a mask).
Def mask(i) = Pow(2, i) ' return a mask of only bit-i set (base 0)
Def set_bit(n, i) = n Bor mask(i) ' set bit-i in n (base 0)
Def reset_bit(n, i) = n Band Bnot(mask(i)) ' reset bit-i in n (base 0)
Def get_bit(n, i) = (n Band mask(i)) <> 0 ' return bit-i status: 0 or 1
Color 15,0
cls
Print "* Set/Reset bit is useful for storing boolean data efficiently."
Print "* The rightmost bit of binary number is bit-0, then bit-1, etc."
Print "* This SB version supports "; Len(Bin(0)); " bits binary numbers."
Print
While True Do
Color 15,0
Input " Enter a number (Enter empty to stop): ", n
If isstring(n) Then
Stop
Endif
Print
Color 14, 0: Print " In Binary is: "; Bin(n)
Color 7, 0: Print " Bit-3 status: "; get_bit(n, 3)
If get_bit(n, 3) Then
Color 11, 0: Print " Reset bit-3: "; Bin(reset_bit(n, 3))
Else
Color 15, 0: Print " Set bit-3: "; Bin(set_bit(n, 3))
Endif
Print
Wend
Code samples using NOR
002 numeric variables.bas
3d rotating cube with message.bas
3d_torus.bas
3dtorus.bas
7gables.bas
anball 1.0.bas
Balleta 2-11-15.bas
betrayal: crows ii.bas
dmsareaplot.bas
dogstar5.bas
Eliza.bas
eliza.bas
ellipse arc length estimate.bas
gaptest.bas
gputmalc.bas
gridareaplot.bas
illuminati.bas
irc-bot.bas
lib-gputmcon.bas
lib-north.bas
pirate.bas
realpolitik.bas
scales132.bas
subversion.bas
sunup.bas
TinyBASIC.bas
tracklog.bas
Language
AND
AS
BAND
BG
BOR
BYREF
CALL
CASE
CATCH
CONST
DECLARE
DEF
DO
ELIF
ELSE
ELSEIF
END
END TRY
ENDIF
EQV
EXIT
FALSE
FI
FOR
FUNC
GOSUB
GOTO
IF
IFF
IMP
IN
LABEL
LET
LIKE
LOCAL
LSHIFT
MDL
MOD
NAND
NEXT
NOR
NOT
ON
OR
REM
REPEAT
RETURN
RSHIFT
SELECT
STEP
STOP
SUB
THEN
THROW
TO
TRUE
TRY
UNTIL
USE
USG
USING
WEND
WHILE
XNOR
XOR
If there is insufficient information on this page and you wish learn more about NOR,
please send an email to smallbasic@gmail.com. You can help to improve information about
NOR by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.