smalltalk
/
osmo-st-sip
Archived
1
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
osmo-st-sip/callagent/Extensions.st

29 lines
944 B
Smalltalk

"
Extensions coming from Pharo
"
ByteArray extend [
hex [
<category: '*PharoCompat'>
" an alternate implementation was | result stream |
result := String new: self size * 2.
stream := result writeStream.
1 to: self size do: [ :ix | |each|
each := self at: ix.
stream
nextPut: ('0123456789ABCDEF' at: each // 16 + 1);
nextPut: ('0123456789ABCDEF' at: each \\ 16 + 1)].
^ result"
"Answer a hexa decimal representation of the receiver"
| string v index map |
map := '0123456789abcdef'.
string := String new: self size * 2. "hex"
index := 0.
1 to: self size do: [ :i |
v := self at: i.
string at: (index := index + 1) put: (map at: (v bitShift: -4) + 1).
string at: (index := index + 1) put: (map at: (v bitAnd: 15) + 1)].
^string
]
]