added #digitByteLength
authorClaus Gittinger <cg@exept.de>
Mon, 26 Oct 1998 17:24:06 +0100
changeset 3890 a024811ed304
parent 3889 3466554b639f
child 3891 1bbab65996ef
added #digitByteLength (similar to #digitByte; but different for negative numbers)
Integer.st
--- a/Integer.st	Thu Oct 22 20:13:36 1998 +0200
+++ b/Integer.st	Mon Oct 26 17:24:06 1998 +0100
@@ -821,6 +821,36 @@
     "Modified: 1.3.1997 / 16:54:23 / cg"
 ! !
 
+!Integer methodsFor:'byte access'!
+
+digitByteLength
+    "return the number bytes required for a 2's complement
+     binary representation of this Integer.
+     For positive receivers, thats the same as the digitLength."
+
+    "
+     check if there is a 0-byte ...
+     this allows to ask unnormalized LargeIntegers 
+     for their digitLength
+    "
+    |l "{ Class: SmallInteger }" |
+
+    self >= 0 ifTrue:[^ self digitLength].
+
+    l := self negated digitLength.
+    (self digitByteAt:l) == 16rFF ifTrue:[
+        ^ (l - 1) max:1
+    ].
+    ^ l
+
+    "
+     -129 digitByteLength 
+    "
+
+    "Created: / 25.10.1998 / 14:58:09 / cg"
+    "Modified: / 25.10.1998 / 19:20:33 / cg"
+! !
+
 !Integer methodsFor:'coercing and converting'!
 
 asFixedPoint
@@ -1604,5 +1634,5 @@
 !Integer class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.86 1998-10-17 16:00:54 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.87 1998-10-26 16:24:06 cg Exp $'
 ! !