setBit/clearBit.
authorClaus Gittinger <cg@exept.de>
Tue, 25 Jan 2000 11:12:20 +0100
changeset 5209 3a52e2f97ec4
parent 5208 7cdbf4e22374
child 5210 f56e448396f9
setBit/clearBit.
Integer.st
SmallInteger.st
--- a/Integer.st	Mon Jan 24 23:48:06 2000 +0100
+++ b/Integer.st	Tue Jan 25 11:12:20 2000 +0100
@@ -491,33 +491,6 @@
      1 >> -5  
      64 >> 5  
     "
-!
-
-isBitSet:index
-    "return true if the index' bit is set; false otherwise.
-     Bits are counted from 1 starting with the least significant."
-
-    ^ (self bitAt:index) ~~ 0
-
-    "
-     5 isBitSet:3       => true
-     2r0101 isBitSet:2  => false
-     2r0101 isBitSet:1  => true
-     2r0101 isBitSet:0  index error
-    "
-!
-
-setBit:index
-    "return a new number where the specified bit is on.
-     Bits are counted from 1 starting with the least significant."
-
-    ^ self bitOr:(1 bitShift:index-1)
-
-    "
-     0 setBit:3         => 4 (2r100)
-     0 setBit:48        => 140737488355328 (2r1000.....000)
-     ((0 setBit:99) setBit:100) printStringRadix:2  
-    "
 ! !
 
 !Integer methodsFor:'bcd conversion'!
@@ -1006,7 +979,9 @@
 
 clearBit:index
     "return a new number where the specified bit is off.
-     Bits are counted from 1 starting with the least significant."
+     Bits are counted from 1 starting with the least significant.
+     The methods name may be missleading: the receiver is not changed,
+     but a new number is returned. Should be named #withBitCleared:"
 
     |n         "{ Class: SmallInteger }"
      byteIndex "{ Class: SmallInteger }"
@@ -1078,6 +1053,20 @@
     "Modified: / 3.5.1999 / 09:20:57 / stefan"
 !
 
+isBitSet:index
+    "return true if the index' bit is set; false otherwise.
+     Bits are counted from 1 starting with the least significant."
+
+    ^ (self bitAt:index) ~~ 0
+
+    "
+     5 isBitSet:3       => true
+     2r0101 isBitSet:2  => false
+     2r0101 isBitSet:1  => true
+     2r0101 isBitSet:0  index error
+    "
+!
+
 lowBit
     "return the bitIndex of the lowest bit set. The returned bitIndex
      starts at 1 for the least significant bit. Returns -1 if no bit is set."
@@ -1149,6 +1138,21 @@
     "
 
     "Created: / 6.6.1999 / 15:00:55 / cg"
+!
+
+setBit:index
+    "return a new number where the specified bit is on.
+     Bits are counted from 1 starting with the least significant.
+     The methods name may be missleading: the receiver is not changed,
+     but a new number is returned. Should be named #withBitCleared:"
+
+    ^ self bitOr:(1 bitShift:index-1)
+
+    "
+     0 setBit:3         => 4 (2r100)
+     0 setBit:48        => 140737488355328 (2r1000.....000)
+     ((0 setBit:99) setBit:100) printStringRadix:2  
+    "
 ! !
 
 !Integer methodsFor:'byte access'!
@@ -2566,6 +2570,6 @@
 !Integer class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.127 2000-01-17 11:13:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.128 2000-01-25 10:12:12 cg Exp $'
 ! !
 Integer initialize!
--- a/SmallInteger.st	Mon Jan 24 23:48:06 2000 +0100
+++ b/SmallInteger.st	Tue Jan 25 11:12:20 2000 +0100
@@ -945,24 +945,26 @@
 
 clearBit:anInteger
     "return a new number where the specified bit is off.
-     Bits are counted from 1 starting with the least significant."
+     Bits are counted from 1 starting with the least significant.
+     The methods name may be missleading: the receiver is not changed,
+     but a new number is returned. Should be named #withBitCleared:"
 
 %{  /* NOCONTEXT */
 
     if (__isSmallInteger(anInteger)) {
-	int index = __intVal(anInteger);
+        int index = __intVal(anInteger);
 
 #ifdef alpha64
-	if (index <= 63)
+        if (index <= 63)
 #else
-	if (index <= 30)
+        if (index <= 30)
 #endif
-	{
-	    INT mask = __MASKSMALLINT(1 << (index-1));
-
-	    RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
-	}
-	RETURN (self);
+        {
+            INT mask = __MASKSMALLINT(1 << (index-1));
+
+            RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
+        }
+        RETURN (self);
     }
 %}.
     ^ self retry:#clearBit: coercing:anInteger
@@ -1274,6 +1276,47 @@
      16r1000000 lowBit 
      0 lowBit 
     "
+!
+
+setBit:anInteger
+    "return a new number where the specified bit is on.
+     Bits are counted from 1 starting with the least significant.
+     The methods name may be missleading: the receiver is not changed,
+     but a new number is returned. Should be named #withBitCleared:"
+
+%{  /* NOCONTEXT */
+
+    if (__isSmallInteger(anInteger)) {
+        int index = __intVal(anInteger);
+
+#ifdef alpha64
+        if (index <= 63)
+#else
+        if (index <= 30)
+#endif
+        {
+            INT mask = __MASKSMALLINT(1 << (index-1));
+
+            RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
+        }
+        RETURN (self);
+    }
+%}.
+    ^ self retry:#setBit: coercing:anInteger
+
+    "
+     (16r401 setBit:2     ) hexPrintString      
+     (16r30000000 setBit:1) hexPrintString     
+     (16r40000000 setBit:0) hexPrintString  
+     (16r0 setBit:29) hexPrintString             
+     (16r0 setBit:30) hexPrintString             
+     (16r0 setBit:31) hexPrintString             
+     (16r0 setBit:32) hexPrintString       
+     (16r0 setBit:33) hexPrintString       
+     (16r0 setBit:100) hexPrintString      
+    "
+
+
 ! !
 
 !SmallInteger methodsFor:'byte access'!
@@ -3115,5 +3158,5 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.125 1999-11-03 09:28:05 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.126 2000-01-25 10:12:20 cg Exp $'
 ! !