View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sum2002 Midterm Review: String to Hex

Edit Sum2002 Midterm Review: String to Hex here.


stringToHex: numberString
"takes in a string of numbers separated by spaces, and
returns an ordered collection of their hexadecimal
equivalents (each number gets converted to a separate
string)."

| integerCollection hexCollection |

integerCollection _ numberString findTokens: ' ' .
hexCollection _ OrderedCollection new .

(1 to: integerCollection size)
do: [ :index |
hexCollection add: (integerCollection at: index) asNumber hex .
] .

^ hexCollection .



this is good, but you can do it in one line, without temporary variables. how? Shaggz


stringToHex: numberString
"smalltalk h4X0r"
^ (numberString findTokens: ' ') collect: [ :element | element asNumber hex ] .



31337 Shaggz

Link to this Page