Fix accessing of bits 8, 16 ...
authorStefan Vogel <sv@exept.de>
Sun, 23 May 1999 20:12:06 +0200
changeset 750 4a5176b04075
parent 749 bbd9b24cee87
child 751 5f8d228a48fd
Fix accessing of bits 8, 16 ... Store bit 1 in bit 8 of byte (for BER).
BoolArray.st
BooleanArray.st
--- a/BoolArray.st	Fri May 21 12:25:18 1999 +0200
+++ b/BoolArray.st	Sun May 23 20:12:06 1999 +0200
@@ -73,6 +73,10 @@
     variable (tally).
     It may be useful if huge boolean arrays are to be used.
 
+    Bits 1 to 8 of the BooleanArray are stored in bits 8 to 1 of the
+    corresponding byte, to allow easy mapping to ASN.1 BIT STRING encoding
+    in the BER.
+
     [memory requirements:]
         OBJ-HEADER + ((size + 7) // 8)
 
@@ -125,8 +129,8 @@
     index > tally ifTrue:[
         ^ self subscriptBoundsError:index
     ].
-    byte := super at:(index // 8) + 1.
-    mask := 1 bitShift:(index \\ 8).
+    byte := super at:((index+7) // 8).
+    mask := 1 bitShift:(7 - (index \\ 8)).
     ^ (byte bitAnd:mask) ~~ 0
 
     "
@@ -141,7 +145,8 @@
      b at:555   
     "
 
-    "Modified: 31.7.1997 / 18:37:25 / cg"
+    "Modified: / 31.7.1997 / 18:37:25 / cg"
+    "Modified: / 23.5.1999 / 20:02:57 / stefan"
 !
 
 at:index put:aBoolean
@@ -153,9 +158,9 @@
         ^ self subscriptBoundsError:index
     ].
 
-    idx := (index // 8) + 1.
+    idx := (index+7) // 8.
     byte := super at:idx.
-    mask := 1 bitShift:(index \\ 8).
+    mask := 1 bitShift:(7 - (index \\ 8)).
     aBoolean ifTrue:[
         byte := byte bitOr:mask
     ] ifFalse:[
@@ -172,7 +177,8 @@
      b at:555   
     "
 
-    "Modified: 31.7.1997 / 18:37:35 / cg"
+    "Modified: / 31.7.1997 / 18:37:35 / cg"
+    "Modified: / 23.5.1999 / 20:02:42 / stefan"
 !
 
 size
@@ -198,5 +204,5 @@
 !BooleanArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/BoolArray.st,v 1.3 1999-03-19 20:41:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/BoolArray.st,v 1.4 1999-05-23 18:12:06 stefan Exp $'
 ! !
--- a/BooleanArray.st	Fri May 21 12:25:18 1999 +0200
+++ b/BooleanArray.st	Sun May 23 20:12:06 1999 +0200
@@ -73,6 +73,10 @@
     variable (tally).
     It may be useful if huge boolean arrays are to be used.
 
+    Bits 1 to 8 of the BooleanArray are stored in bits 8 to 1 of the
+    corresponding byte, to allow easy mapping to ASN.1 BIT STRING encoding
+    in the BER.
+
     [memory requirements:]
         OBJ-HEADER + ((size + 7) // 8)
 
@@ -125,8 +129,8 @@
     index > tally ifTrue:[
         ^ self subscriptBoundsError:index
     ].
-    byte := super at:(index // 8) + 1.
-    mask := 1 bitShift:(index \\ 8).
+    byte := super at:((index+7) // 8).
+    mask := 1 bitShift:(7 - (index \\ 8)).
     ^ (byte bitAnd:mask) ~~ 0
 
     "
@@ -141,7 +145,8 @@
      b at:555   
     "
 
-    "Modified: 31.7.1997 / 18:37:25 / cg"
+    "Modified: / 31.7.1997 / 18:37:25 / cg"
+    "Modified: / 23.5.1999 / 20:02:57 / stefan"
 !
 
 at:index put:aBoolean
@@ -153,9 +158,9 @@
         ^ self subscriptBoundsError:index
     ].
 
-    idx := (index // 8) + 1.
+    idx := (index+7) // 8.
     byte := super at:idx.
-    mask := 1 bitShift:(index \\ 8).
+    mask := 1 bitShift:(7 - (index \\ 8)).
     aBoolean ifTrue:[
         byte := byte bitOr:mask
     ] ifFalse:[
@@ -172,7 +177,8 @@
      b at:555   
     "
 
-    "Modified: 31.7.1997 / 18:37:35 / cg"
+    "Modified: / 31.7.1997 / 18:37:35 / cg"
+    "Modified: / 23.5.1999 / 20:02:42 / stefan"
 !
 
 size
@@ -198,5 +204,5 @@
 !BooleanArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/BooleanArray.st,v 1.3 1999-03-19 20:41:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/BooleanArray.st,v 1.4 1999-05-23 18:12:06 stefan Exp $'
 ! !