NBITS/de
(→Example) |
(→See Also) |
||
Line 60: | Line 60: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Siehe auch</span> = |
[[BITS]] | [[BITS]] |
Revision as of 01:07, 1 March 2013
Contents |
= (**COPIED FROM ENGLISH PAGE**) === Action
Set all except the specified bits to 1.
Syntax
Var = NBITS( b1 [,bn])
Remarks
Var |
The BYTE/PORT variable that is assigned with the constant. |
B1 , bn |
A list of bit numbers that NOT must be set to 1. |
While it is simple to assign a value to a byte, and there is special Boolean notation &B for assigning bits, the Bits() and NBits() function makes it simple to assign a few bits.
B = &B01111101 : how many zero’s are there?
This would make it more readable: B = NBits(1, 7)
You can read from the code that bit 1 and bit 7 are NOT set to 1.
It does not save code space as the effect is the same.
The NBITS() function will set all bits to 1 except for the specified bits.
It can only be used on bytes and port registers.
Valid bits are in range from 0 to 7.
Siehe auch
Beispiel
'-------------------------------------------------------------------------------- 'name : bits-nbits.bas 'copyright : (c) 1995-2005, MCS Electronics 'purpose : demo for Bits() AND Nbits() 'micro : Mega48 'suited for demo : yes 'commercial addon needed : no 'use in simulator : possible '-------------------------------------------------------------------------------- $regfile = "m48def.dat" ' specify the used micro $crystal = 4000000 ' Taktfrequenz $baud = 19200 ' Baudrate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space Dim B As Byte 'Man kann die &B Notation zum Setzen von Bits benutzen B = &B1000_0111 'Deutlicher ist es, die zu setzenden Bits mit der BITS() Funktion anzugeben: B = Bits(0 , 1 , 2 , 7) 'setzt nur die Bits 0,1,2 und 7 Print B 'Während bits() alle genannten Bits auf 1 setzt gibt es auch Nbits() 'Das N steht für NOT. Nbits(1,2) bedeutet, dass alle Bits außer 1 und 2 gesetzt werden. B = Nbits(7) 'Setze NICHT 7 Print B End
Languages | English • Deutsch |
---|