1056 ! |
1058 ! |
1057 |
1059 |
1058 asImmutableByteArray |
1060 asImmutableByteArray |
1059 "return a write-protected copy of myself" |
1061 "return a write-protected copy of myself" |
1060 |
1062 |
1061 ^ self copy changeClassTo:ImmutableByteArray |
1063 |copy| |
|
1064 |
|
1065 copy := self copy. |
|
1066 copy class == ByteArray ifTrue:[ |
|
1067 ^ copy changeClassTo:ImmutableByteArray. |
|
1068 ] ifFalse:[ |
|
1069 ^ self shouldNotImplement. |
|
1070 ]. |
1062 ! |
1071 ! |
1063 |
1072 |
1064 asInteger |
1073 asInteger |
1065 "convert myself to an integer - the first byte is most significant. |
1074 "convert myself to an integer - the first byte is most significant. |
1066 This is also in Squeak." |
1075 This is also in Squeak." |
1079 This is also in Squeak." |
1088 This is also in Squeak." |
1080 |
1089 |
1081 ^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed |
1090 ^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed |
1082 |
1091 |
1083 " |
1092 " |
1084 (#[ 2 ] asIntegerMSB:true) hexPrintString |
1093 (#[ 2 ] asIntegerMSB:true) hexPrintString |
1085 (#[ 16r1 16r2 ] asIntegerMSB:true) hexPrintString |
1094 (#[ 16r1 16r2 ] asIntegerMSB:true) hexPrintString |
1086 (#[ 16r1 16r2 ] asIntegerMSB:false) hexPrintString |
1095 (#[ 16r1 16r2 ] asIntegerMSB:false) hexPrintString |
1087 (#[4 0 0 0 0 0 0 0] asIntegerMSB:true) hexPrintString |
1096 (#[4 0 0 0 0 0 0 0 0 0 0 0] asIntegerMSB:true) hexPrintString |
1088 " |
1097 " |
1089 ! |
1098 ! |
1090 |
1099 |
1091 asPackedString |
1100 asPackedString |
1092 "ST-80 compatibility: encode the receiver into an ascii String |
1101 "ST-80 compatibility: encode the receiver into an ascii String |
1159 " |
1168 " |
1160 |
1169 |
1161 "Modified: 12.11.1996 / 15:45:02 / cg" |
1170 "Modified: 12.11.1996 / 15:45:02 / cg" |
1162 ! |
1171 ! |
1163 |
1172 |
|
1173 asSignedByteArray |
|
1174 "return the receiver as a signed byteArray. |
|
1175 elements > 127 are converted to negative numbers." |
|
1176 |
|
1177 |cls| |
|
1178 |
|
1179 cls := self class. |
|
1180 "could be an instance of a subclass..." |
|
1181 (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[ |
|
1182 ^ self copy changeClassTo:SignedByteArray. |
|
1183 ]. |
|
1184 ^ super asSignedByteArray |
|
1185 |
|
1186 " |
|
1187 'hello world' asSignedByteArray |
|
1188 #[1 2 3 4 5 6 7] asSignedByteArray |
|
1189 #[1 2 129 4 5 6 7] asSignedByteArray |
|
1190 " |
|
1191 ! |
|
1192 |
1164 beImmutable |
1193 beImmutable |
1165 "make myself write-protected" |
1194 "make myself write-protected" |
1166 |
1195 |
1167 self changeClassTo:ImmutableByteArray |
1196 self class == ByteArray ifTrue:[ |
|
1197 self changeClassTo:ImmutableByteArray. |
|
1198 ] ifFalse:[ |
|
1199 self shouldNotImplement. |
|
1200 ]. |
|
1201 ! |
|
1202 |
|
1203 beSigned |
|
1204 "make mayself signed. |
|
1205 elements > 127 are converted to negative numbers." |
|
1206 |
|
1207 self class == ByteArray ifTrue:[ |
|
1208 self changeClassTo:SignedByteArray. |
|
1209 ] ifFalse:[ |
|
1210 self shouldNotImplement. |
|
1211 ]. |
|
1212 |
|
1213 " |
|
1214 #[ 1 2 3 128 255] copy beSigned |
|
1215 " |
|
1216 ! |
|
1217 |
|
1218 beUnsigned |
|
1219 "thats what I am (but I don't know if this is true for subclasses." |
|
1220 |
|
1221 self class == ByteArray ifTrue:[ |
|
1222 ^ self. |
|
1223 ] ifFalse:[ |
|
1224 self shouldNotImplement. |
|
1225 ]. |
|
1226 |
|
1227 " |
|
1228 #[ 1 2 3 128 255] copy beUnsigned |
|
1229 " |
1168 ! |
1230 ! |
1169 |
1231 |
1170 decodeAsLiteralArray |
1232 decodeAsLiteralArray |
1171 "given a literalEncoding in the receiver, |
1233 "given a literalEncoding in the receiver, |
1172 create & return the corresponding object. |
1234 create & return the corresponding object. |
2927 " |
2989 " |
2928 #[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues |
2990 #[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues |
2929 " |
2991 " |
2930 ! ! |
2992 ! ! |
2931 |
2993 |
|
2994 |
2932 !ByteArray methodsFor:'searching'! |
2995 !ByteArray methodsFor:'searching'! |
2933 |
2996 |
2934 indexOf:aByte startingAt:start |
2997 indexOf:aByte startingAt:start |
2935 "return the index of the first occurrence of the argument, aByte |
2998 "return the index of the first occurrence of the argument, aByte |
2936 in the receiver starting at start, anInteger; return 0 if not found. |
2999 in the receiver starting at start, anInteger; return 0 if not found. |