SmallInteger.st
changeset 8937 4f2508548327
parent 8919 707a9ff7f9b2
child 10342 58ce3aabaa4b
equal deleted inserted replaced
8936:e098919f2f79 8937:4f2508548327
  1021 %}.
  1021 %}.
  1022     ^ self retry:#bitXor: coercing:anInteger
  1022     ^ self retry:#bitXor: coercing:anInteger
  1023 !
  1023 !
  1024 
  1024 
  1025 clearBit:anInteger
  1025 clearBit:anInteger
  1026     "return a new number where the specified bit is off.
  1026     "return a new integer where the specified bit is off.
  1027      Bits are counted from 1 starting with the least significant.
  1027      Bits are counted from 1 starting with the least significant.
  1028      The methods name may be missleading: the receiver is not changed,
  1028      The methods name may be missleading: the receiver is not changed,
  1029      but a new number is returned. Should be named #withBitCleared:"
  1029      but a new number is returned. Should be named #withBitCleared:"
  1030 
  1030 
  1031 %{  /* NOCONTEXT */
  1031 %{  /* NOCONTEXT */
  1032 
  1032 
  1033     if (__isSmallInteger(anInteger)) {
  1033     if (__isSmallInteger(anInteger)) {
  1034 	int index = __intVal(anInteger);
  1034         int index = __intVal(anInteger);
  1035 
  1035 
  1036 	if (index > 0) {
  1036         if (index > 0) {
  1037 #if __POINTER_SIZE__ == 8
  1037 #if __POINTER_SIZE__ == 8
  1038 	    if (index <= 62)
  1038             if (index <= 62)
  1039 #else
  1039 #else
  1040 	    if (index <= 30)
  1040             if (index <= 30)
  1041 #endif
  1041 #endif
  1042 	    {
  1042             {
  1043 		INT mask = __MASKSMALLINT(1 << (index-1));
  1043                 INT mask = __MASKSMALLINT(1 << (index-1));
  1044 
  1044 
  1045 		RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
  1045                 RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
  1046 	    }
  1046             }
  1047 	    RETURN (self);  /* nothing to do ... */
  1047             RETURN (self);  /* nothing to do ... */
  1048 	}
  1048         }
  1049     }
  1049     }
  1050 %}.
  1050 %}.
  1051     ^ super clearBit:anInteger
  1051     ^ super clearBit:anInteger
  1052 
  1052 
  1053     "
  1053     "
  1064      (16rF0000001 clearBit:29) hexPrintString
  1064      (16rF0000001 clearBit:29) hexPrintString
  1065      (16rF0000001 clearBit:30) hexPrintString
  1065      (16rF0000001 clearBit:30) hexPrintString
  1066      (16rF0000001 clearBit:31) hexPrintString
  1066      (16rF0000001 clearBit:31) hexPrintString
  1067      (16rF0000001 clearBit:32) hexPrintString
  1067      (16rF0000001 clearBit:32) hexPrintString
  1068     "
  1068     "
  1069 
       
  1070 
       
  1071 !
  1069 !
  1072 
  1070 
  1073 highBit
  1071 highBit
  1074     "return the bitIndex of the highest bit set. The returned bitIndex
  1072     "return the bitIndex of the highest bit set. The returned bitIndex
  1075      starts at 1 for the least significant bit.
  1073      starts at 1 for the least significant bit.
  1309      ]
  1307      ]
  1310     "
  1308     "
  1311 !
  1309 !
  1312 
  1310 
  1313 setBit:anInteger
  1311 setBit:anInteger
  1314     "return a new number where the specified bit is on.
  1312     "return a new integer where the specified bit is on.
  1315      Bits are counted from 1 starting with the least significant.
  1313      Bits are counted from 1 starting with the least significant.
  1316      The methods name may be missleading: the receiver is not changed,
  1314      The methods name may be missleading: the receiver is not changed,
  1317      but a new number is returned. Should be named #withBitSet:"
  1315      but a new number is returned. Should be named #withBitSet:"
  1318 
  1316 
  1319 %{  /* NOCONTEXT */
  1317 %{  /* NOCONTEXT */
  1320 
  1318 
  1321     if (__isSmallInteger(anInteger)) {
  1319     if (__isSmallInteger(anInteger)) {
  1322 	int index = __intVal(anInteger);
  1320         int index = __intVal(anInteger);
  1323 
  1321 
  1324 	if (index > 0) {
  1322         if (index > 0) {
  1325 #if __POINTER_SIZE__ == 8
  1323 #if __POINTER_SIZE__ == 8
  1326 	    if (index <= 62)
  1324             if (index <= 62)
  1327 #else
  1325 #else
  1328 	    if (index <= 30)
  1326             if (index <= 30)
  1329 #endif
  1327 #endif
  1330 	    {
  1328             {
  1331 		INT mask = __MASKSMALLINT(1 << (index-1));
  1329                 INT mask = __MASKSMALLINT(1 << (index-1));
  1332 
  1330 
  1333 		RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
  1331                 RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
  1334 	    }
  1332             }
  1335 	}
  1333         }
  1336     }
  1334     }
  1337 %}.
  1335 %}.
  1338     ^ super setBit:anInteger
  1336     ^ super setBit:anInteger
  1339 
  1337 
  1340     "
  1338     "
  1346      (16r0 setBit:31) hexPrintString
  1344      (16r0 setBit:31) hexPrintString
  1347      (16r0 setBit:32) hexPrintString
  1345      (16r0 setBit:32) hexPrintString
  1348      (16r0 setBit:33) hexPrintString
  1346      (16r0 setBit:33) hexPrintString
  1349      (16r0 setBit:100) hexPrintString
  1347      (16r0 setBit:100) hexPrintString
  1350     "
  1348     "
  1351 
       
  1352 
       
  1353 ! !
  1349 ! !
  1354 
  1350 
  1355 !SmallInteger methodsFor:'bit operators-32bit'!
  1351 !SmallInteger methodsFor:'bit operators-32bit'!
  1356 
  1352 
  1357 asUnsigned32
  1353 asUnsigned32
  3578 ! !
  3574 ! !
  3579 
  3575 
  3580 !SmallInteger class methodsFor:'documentation'!
  3576 !SmallInteger class methodsFor:'documentation'!
  3581 
  3577 
  3582 version
  3578 version
  3583     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.166 2005-07-08 21:13:39 cg Exp $'
  3579     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.167 2005-07-26 14:24:24 cg Exp $'
  3584 ! !
  3580 ! !