<p>The solution can be like this for <code>asByteArrayOfSize:</code> and <code>asByteArray</code> is pretty similar:</p>
<pre><code>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.
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AhLyW2NagY8REvPV0uXwFA9NEzqzyvAJks5u6lk7gaJpZM4ZaZ2D">mute the thread</a>.<img src="https://github.com/notifications/beacon/AhLyWwCBGuNy_P26jNo79AxeXMtCuOqMks5u6lk7gaJpZM4ZaZ2D.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@maximvl in #324: The solution can be like this for `asByteArrayOfSize:` and `asByteArray` is pretty similar:\r\n```\r\nnegative := self negative.\r\nnegative \r\n\tifTrue: [\r\n\t\tnumber := self + 1.\r\n\t\tanswer := ByteArray new: aSize withAll: 255 ]\r\n\tifFalse: [\r\n                number := self.\r\n\t\tanswer := ByteArray new: aSize. ].\r\n\r\ndigitPos := 1.\r\naSize \r\n\tto: aSize - number digitLength + 1\r\n\tby: -1\r\n\tdo: \r\n\t\t[ :pos | \r\n\t\tanswer \r\n\t\t\tat: pos\r\n\t\t\tput: (\r\n\t\t\t\tnegative \r\n\t\t\t\t\tifTrue: [ 255 - (number digitAt: digitPos) ]\r\n\t\t\t\t\tifFalse: [ number digitAt: digitPos ]\r\n\t\t\t).\r\n\t\tdigitPos := digitPos + 1 ].\r\n^ answer.\r\n```"}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>