SmallInteger.st
changeset 1336 041485f6757a
parent 1295 83f594f05c52
child 1506 3b4ff5941981
--- a/SmallInteger.st	Tue May 07 08:33:38 1996 +0200
+++ b/SmallInteger.st	Tue May 07 09:08:58 1996 +0200
@@ -1012,6 +1012,50 @@
     "return the generality value - see ArithmeticValue>>retry:coercing:"
 
     ^ 20
+!
+
+signExtendedByteValue
+    "return a smallInteger from sign-extending the 8'th bit.
+     May be useful for communication interfaces"
+
+%{  /* NOCONTEXT */
+    int i = __intVal(self);
+
+    if (i & 0x80) {
+        i = i | 0x7FFFFF00;
+    } else {
+        i = i & 0x7F;
+    }
+
+    RETURN (__MKSMALLINT(i));
+%}
+
+    "
+     16rFF signExtendedByteValue
+     16r7F signExtendedByteValue
+    "
+!
+
+signExtendedShortValue
+    "return a smallInteger from sign-extending the 16'th bit.
+     May be useful for communication interfaces"
+
+%{  /* NOCONTEXT */
+    int i = __intVal(self);
+
+    if (i & 0x8000) {
+        i = i | 0x7FFF0000;
+    } else {
+        i = i & 0x7FFF;
+    }
+
+    RETURN (__MKSMALLINT(i));
+%}
+
+    "
+     16rFFFF signExtendedShortValue
+     16r7FFF signExtendedShortValue
+    "
 ! !
 
 !SmallInteger methodsFor:'comparing'!
@@ -2017,5 +2061,5 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.51 1996-04-25 16:58:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.52 1996-05-07 07:08:58 cg Exp $'
 ! !