Difference between revisions of "Not"
From Free Pascal wiki
Jump to navigationJump to searchm (Text replace - "pascal>" to "syntaxhighlight>") |
|||
Line 23: | Line 23: | ||
== Ones' complement == | == Ones' complement == | ||
− | < | + | <syntaxhighlight> |
function OnesComplement ( const aValue : byte ): byte; | function OnesComplement ( const aValue : byte ): byte; | ||
begin | begin | ||
result := Not AValue; | result := Not AValue; | ||
end; | end; | ||
− | </ | + | </syntaxhighlight> |
If you call OnesComplement([[Percent sign|%]]10000000) then get %01111111 (%10000000 = 128 and %01111111 = 127). If you call OnesComplement(%00000111) then get 248 (248 = %11111000). | If you call OnesComplement([[Percent sign|%]]10000000) then get %01111111 (%10000000 = 128 and %01111111 = 127). If you call OnesComplement(%00000111) then get 248 (248 = %11111000). | ||
− | < | + | <syntaxhighlight> |
function OnesComplement2 ( const aValue : shortint ): shortint; | function OnesComplement2 ( const aValue : shortint ): shortint; | ||
begin | begin | ||
result := Not AValue; | result := Not AValue; | ||
end; | end; | ||
− | </ | + | </syntaxhighlight> |
If you call OnesComplement2(%00000010) then get %11111101 (%00000010 = 2 and %11111101 = -3 when [[Type|type]] is shortint). If you call OnesComplement2(7) then get -8 (-8 = %11111000 when type is shortint and 7 = %00000111 ). | If you call OnesComplement2(%00000010) then get %11111101 (%00000010 = 2 and %11111101 = -3 when [[Type|type]] is shortint). If you call OnesComplement2(7) then get -8 (-8 = %11111000 when type is shortint and 7 = %00000111 ). |
Revision as of 00:51, 25 March 2012
Boolean operation
Not produces a value of true if original value is false.
Truth table
A | Not A |
---|---|
false | true |
true | false |
Bitwise operation
Bitwise not sets the bit to 1 if corresponding bit is 0, and to 0 if bit is 1.
Ones' complement
function OnesComplement ( const aValue : byte ): byte;
begin
result := Not AValue;
end;
If you call OnesComplement(%10000000) then get %01111111 (%10000000 = 128 and %01111111 = 127). If you call OnesComplement(%00000111) then get 248 (248 = %11111000).
function OnesComplement2 ( const aValue : shortint ): shortint;
begin
result := Not AValue;
end;
If you call OnesComplement2(%00000010) then get %11111101 (%00000010 = 2 and %11111101 = -3 when type is shortint). If you call OnesComplement2(7) then get -8 (-8 = %11111000 when type is shortint and 7 = %00000111 ).