共用方式為


valarray::operator~

位元取得每個項目的 NOT 值。valarray 的一元 (Unary) 運算子。

valarray<Type> operator~( ) const;

傳回值

位元欄位就是運算元中的項目值 NOT valarray valarray 的布林值。

備註

作業只能位元作業中使用位元 char 和 int 資料型別和變數和不在 floatdoublelongdouble, void, bool ),更複雜的資料型別。

NOT 具備位元的事實資料表和邏輯 NOT 相同,但適用於對兩個數值層級上的資料型別。 所指定的位元 b, ~b 為 True,如果 b 屬於錯誤和錯誤的,如果 b 則為 true。 邏輯 NOT運算子! 項目層級上套用,計算為任何非零的值, true,而結果是 valarray 布林值。 除了之外, 0 或 1 位元 NOToperator~,相較之下,可能會導致 valarray 位元值,根據作業的結果。

範例

// valarray_op_bitnot.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>

int main( )
{
   using namespace std;
   int i;

   valarray<unsigned short int> vaL1 ( 10 );
   valarray<unsigned short int> vaNOT1 ( 10 );
   for ( i = 0 ; i < 10 ; i += 2 )
      vaL1 [ i ] =  i;
   for ( i = 1 ; i < 10 ; i += 2 )
      vaL1 [ i ] =  5*i;
   
   cout << "The initial valarray <unsigned short int> is:  ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaL1 [ i ] << " ";
   cout << ")." << endl;

   vaNOT1 = ~vaL1;
   cout << "The element-by-element result of "
        << "the bitwise NOT operator~ is the\n valarray: ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaNOT1 [ i ] << " ";
   cout << ")." << endl << endl;

   valarray<int> vaL2 ( 10 );
   valarray<int> vaNOT2 ( 10 );
   for ( i = 0 ; i < 10 ; i += 2 )
      vaL2 [ i ] =  i;
   for ( i = 1 ; i < 10 ; i += 2 )
      vaL2 [ i ] =  -2 * i;
   
   cout << "The initial valarray <int> is:  ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaL2 [ i ] << " ";
   cout << ")." << endl;

   vaNOT2 = ~vaL2;
   cout << "The element-by-element result of "
        << "the bitwise NOT operator~ is the\n valarray: ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaNOT2 [ i ] << " ";
   cout << ")." << endl;

   // The negative numbers are represented using
   // the two's complement approach, so adding one
   // to the flipped bits returns the negative elements
   vaNOT2 = vaNOT2 + 1;
   cout << "The element-by-element result of "
        << "adding one\n is the negative of the "
        << "original elements the\n valarray: ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaNOT2 [ i ] << " ";
   cout << ")." << endl;
}
  
  
  
  
  

需求

標題: <valarray>

命名空間: std

請參閱

參考

valarray Class