[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

Maxim V notifications at github.com
Wed Dec 19 15:20:28 UTC 2018


The solution can be like this for `asByteArrayOfSize:` and `asByteArray` is pretty similar:
```
negative := self negative.
negative 
	ifTrue: [
		number := self + 1.
		answer := ByteArray new: aSize withAll: 255 ]
	ifFalse: [
                number := self.
		answer := ByteArray new: aSize. ].

digitPos := 1.
aSize 
	to: aSize - number digitLength + 1
	by: -1
	do: 
		[ :pos | 
		answer 
			at: pos
			put: (
				negative 
					ifTrue: [ 255 - (number digitAt: digitPos) ]
					ifFalse: [ number digitAt: digitPos ]
			).
		digitPos := digitPos + 1 ].
^ answer.
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20181219/8bc6c6c2/attachment.html>


More information about the Vm-dev mailing list