script to convert decimal to hexadecimal

My apologies in advance for my ignorance on this–this problem is beyond my limited scripting skills! I need to convert a data stream (system exclusive messages for a MIDI keyboard) from decimal to hex. The data looks like this:

240 15 2 0 7 4 13 4 1 247 240…

And should look like this:

F0 0F 02 00 07 04 0D 04 01 F7 F0…

This is something I found on the net that will do the conversion in applescript (I’ve got it plugged into automator) but I can’t figure out how to have the script read the entire string, parse/convert the bytes and add leading zeros where necessary (i.e. with 7 instead of writing the byte as 7 it must be 07). I would be really grateful for any assistance!
Andrew


on run {input, parameters}
	
	set nDec to 240
	set nHex to do shell script "perl -e 'printf(\"%X\", " & nDec & ")'" --> "F0"
	return nHex
end run

Here’s another one that seems like it should work (but I couldn’t put the front and back on it to do so!)

on toHex(num)
	set str to ""
	set lst to {"A", "B", "C", "D", "E", "F"}
	repeat while (num is greater than 0)
		set m to num mod 16
		if m is greater than 9 then set m to item (m - 9) of lst
		set str to (m as string) & str
		set num to num div 16
	end repeat
	return str
end toHex

Something you’re looking for is like this I guess:

set hexChars to "0123456789ABCDEF"
set midiStream to "240 15 2 0 7 4 13 4 1 247 240"
set hexValues to {}
repeat with byteString in words of midiStream
	set byteValue to byteString as integer
	set hexString to character (byteValue div 16 + 1) of hexChars & character (byteValue mod 16 + 1) of hexChars
	set end of hexValues to hexString
end repeat

set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set outputStream to hexValues as string
set AppleScript's text item delimiters to oldTIDs
return outputStream

BRILLIANT–I’m SO GRATEFUL! Thanks to your script and some insane routing through the netherworld of OS9 I can recover a series of sequences I created on my ESQ-1 25 years ago and I was certain were lost. This is some serious time travel…

Just one note: It takes quite a long time to process longer strings: The time taken seems to increase exponentially as the length of the string increases. But heck, as long as it does the work I can wait! Many many many thanks again. Andrew

I’m off and running, but in fact it is taking quite a while, so if you have any ideas about speed increases they would be most welcome. The stream below, for example, took 548 seconds (on a fast machine, with fans blazing). Shorter streams go very fast–were I to chop this in half it would probably go in a couple of seconds. Any ideas? Thanks.

240 15 2 0 7 10 8 6 1 247 240 15 2 0 8 6 1 10 8 0 0 0 3 13 1 0 0 0 0 10 0 15 5 6 7 2 11 14 7 8 0 0 7 14 7 0 3 0 7 8 7 14 3 0 7 10 6 2 7 1 11 14 7 7 2 0 15 14 7 15 15 0 12 14 7 15 15 0 12 14 7 5 15 1 0 14 1 9 14 11 8 14 1 8 14 13 0 8 1 6 3 12 13 13 0 12 0 12 1 9 14 12 8 14 1 0 11 5 0 12 0 14 1 1 14 13 8 14 1 0 14 7 0 2 1 14 1 8 11 9 0 6 0 6 3 12 12 4 2 12 0 14 1 0 11 3 0 6 0 12 1 9 13 4 8 14 1 8 12 3 0 6 0 14 1 1 14 6 0 6 0 14 1 0 14 5 0 6 0 14 1 1 11 6 0 6 0 14 1 8 13 6 0 6 0 6 3 4 12 13 9 1 2 1 14 6 0 6 0 14 1 0 11 6 0 6 0 12 1 1 14 4 0 6 0 14 1 1 15 11 8 14 1 0 13 3 0 6 0 14 1 0 14 5 0 6 0 10 2 0 14 4 0 6 0 6 3 12 12 12 0 6 0 10 2 0 15 3 0 6 0 14 1 8 11 6 0 6 0 6 3 4 10 1 9 11 3 10 13 4 8 2 4 10 12 4 8 13 3 2 13 3 0 6 0 10 2 8 14 4 0 6 0 11 3 10 13 2 8 9 3 10 11 1 8 0 4 10 10 2 8 12 1 9 11 4 0 6 0 11 3 10 13 8 8 2 4 10 14 9 8 0 4 2 13 1 8 14 1 9 14 11 8 14 1 0 14 5 0 12 0 14 1 0 13 3 0 6 0 14 1 8 14 6 0 6 0 6 3 4 12 4 10 10 2 0 15 5 0 6 0 14 1 0 13 3 0 6 0 12 1 1 14 7 8 14 1 0 14 8 0 12 0 14 1 9 13 13 8 14 1 0 14 10 0 8 1 6 3 12 12 9 9 10 2 0 15 10 0 2 1 12 1 9 8 3 8 10 2 0 14 7 0 6 0 14 1 1 15 7 8 14 1 8 14 6 0 12 0 14 1 9 13 6 8 14 1 0 14 3 0 6 0 14 1 0 14 7 0 6 0 6 3 4 15 5 9 1 2 1 14 7 8 10 2 8 14 4 0 6 0 14 1 8 11 5 0 6 0 12 1 1 6 2 8 14 1 8 14 8 0 6 0 14 1 1 15 6 0 6 0 14 1 8 13 8 0 6 0 6 3 12 14 7 8 1 2 1 15 5 0 12 0 3 2 9 10 6 0 6 0 10 2 8 13 8 0 6 0 5 2 1 14 7 0 6 0 6 3 4 11 3 0 6 0 6 3 4 14 6 8 12 1 9 9 2 0 6 0 9 3 2 11 5 8 2 4 2 12 7 8 14 3 2 12 8 8 14 1 9 14 9 8 14 1 8 14 5 0 12 0 14 1 8 10 2 0 6 0 2 4 10 11 7 10 13 3 10 12 7 10 8 3 10 8 8 10 14 1 0 14 5 0 6 0 6 3 4 15 3 10 10 2 0 14 5 0 6 0 14 1 0 11 3 0 6 0 12 1 9 13 7 8 14 1 0 13 6 0 12 0 14 1 1 12 11 8 14 1 0 12 8 0 8 1 6 3 12 15 10 9 10 2 8 14 8 0 12 0 13 2 10 11 3 8 6 3 2 12 3 8 2 3 10 10 4 0 6 0 1 3 2 14 6 8 6 3 2 13 6 8 12 2 10 11 3 8 12 1 1 12 3 8 14 1 0 12 3 0 6 0 14 1 1 15 7 8 14 1 8 12 6 0 12 0 14 1 9 14 8 8 14 1 8 11 3 0 6 0 10 2 8 14 5 0 6 0 6 3 12 14 11 9 1 2 9 11 10 0 6 0 10 2 8 13 5 0 6 0 12 1 9 8 3 0 6 0 14 1 1 15 5 8 14 1 0 14 4 0 6 0 10 2 8 12 4 0 6 0 6 3 12 12 12 8 14 1 1 11 7 8 10 2 0 12 6 0 6 0 14 1 0 10 7 0 6 0 14 1 9 14 3 1 2 0 1 11 3 4 5 15 1 0 1 11 13 4 1 11 11 5 5 15 1 0 1 11 9 6 1 11 5 7 5 15 1 0 1 11 14 7 1 11 15 7 5 15 1 0 10 2 0 14 6 0 7 0 1 11 12 6 1 11 11 4 5 15 1 0 1 11 0 4 5 15 4 0 6 3 4 15 11 9 10 2 0 13 4 0 6 0 12 1 1 13 5 8 10 2 0 13 5 0 6 0 14 1 1 12 2 8 14 1 8 11 7 0 6 0 14 1 1 15 13 0 6 0 14 1 0 11 3 0 6 0 14 1 8 9 6 0 6 0 6 3 4 15 11 10 10 2 8 13 5 0 12 0 3 2 9 12 0 9 1 12 12 1 1 12 4 3 5 15 1 0 1 12 4 4 1 12 12 4 5 15 1 0 1 12 1 5 1 12 4 5 5 15 1 0 1 12 8 5 1 12 11 5 5 15 1 0 1 12 14 5 1 12 3 6 5 15 1 0 1 12 10 6 1 12 0 7 5 15 1 0 1 12 6 7 1 12 10 7 14 1 8 11 8 0 1 0 1 12 12 7 5 15 1 0 1 12 7 7 5 15 1 0 1 12 1 7 1 12 10 6 5 15 1 0 1 12 0 6 1 12 5 5 5 15 1 0 1 12 7 4 1 12 11 3 5 15 1 0 1 12 1 3 1 12 10 2 5 15 1 0 1 12 2 2 1 12 9 1 5 15 1 0 1 12 0 1 1 12 5 0 5 15 1 0 1 12 0 0 5 15 3 0 1 2 1 14 4 8 14 1 0 10 6 0 12 0 3 2 1 13 5 8 14 1 8 12 7 0 6 0 6 3 12 14 10 9 1 2 1 14 4 8 10 2 8 13 8 0 12 0 14 1 1 15 4 0 6 0 1 2 1 14 3 8 10 2 0 14 4 0 6 0 1 2 1 14 8 8 14 1 8 11 4 0 6 0 6 3 2 12 3 8 15 2 2 11 3 8 1 3 2 13 3 0 6 0 6 3 12 14 3 8 11 3 4 14 3 8 14 1 1 11 2 8 14 1 8 11 3 0 6 0 6 3 12 13 3 8 11 3 12 13 4 8 15 2 10 12 3 8 13 2 2 11 3 8 1 2 9 14 4 8 14 1 8 11 4 0 6 0 4 3 2 14 2 8 10 2 0 14 5 0 6 0 9 3 4 14 3 8 15 2 10 12 2 8 6 3 2 13 3 8 12 1 9 12 3 0 6 0 2 3 2 5 1 8 7 1 9 15 5 0 6 0 9 3 4 14 2 8 4 3 2 13 2 8 11 3 10 13 3 8 6 3 10 9 1 8 14 1 1 14 4 8 14 1 8 12 7 0 6 0 9 3 4 15 2 8 13 3 4 14 3 0 6 0 9 3 10 14 2 8 0 4 10 12 2 8 2 1 1 15 5 8 14 1 8 13 5 0 6 0 11 3 4 15 2 8 0 4 12 10 2 8 12 1 9 12 3 0 6 0 9 3 2 13 2 8 11 3 10 12 2 8 14 1 1 14 4 8 14 1 8 13 6 0 6 0 15 2 5 14 2 8 11 3 12 15 2 8 0 4 4 13 2 8 0 4 10 9 1 8 11 3 2 13 2 8 9 3 2 12 2 8 10 2 0 13 9 0 6 0 15 2 13 13 4 8 11 3 12 15 3 8 0 4 4 13 2 8 9 3 2 14 2 8 11 3 2 14 2 8 0 4 2 13 3 8 14 1 9 14 5 0 6 0 13 2 13 15 3 8 0 4 10 14 2 8 11 3 2 15 1 8 13 3 2 15 2 8 1 4 2 8 1 8 12 1 1 12 4 0 6 0 13 3 2 15 2 8 2 4 2 15 1 8 15 3 10 12 1 8 14 1 0 13 3 0 6 0 14 1 9 14 13 8 14 1 0 12 4 0 6 0 14 1 8 12 4 0 6 0 14 1 0 12 3 0 6 0 14 1 0 12 4 0 6 0 6 3 12 14 14 9 10 2 0 14 8 0 12 0 12 1 1 14 10 8 14 1 8 12 3 0 6 0 14 1 0 14 5 0 6 0 14 1 9 13 11 0 6 0 14 1 8 14 4 0 12 0 14 1 0 13 5 0 6 0 6 3 12 14 15 9 10 2 0 14 9 0 2 1 12 1 9 10 3 0 6 0 14 1 1 14 7 0 6 0 8 2 0 15 4 0 6 0 3 2 4 15 11 8 14 1 9 12 6 0 6 0 10 2 8 12 5 0 6 0 6 3 4 14 3 8 14 1 9 11 4 8 1 2 1 12 10 8 3 2 0 14 5 0 6 0 3 2 4 15 10 0 6 0 12 1 1 11 3 8 10 2 0 12 3 0 6 0 6 3 12 11 4 8 14 1 1 14 10 8 5 2 8 14 7 0 6 0 3 2 4 15 8 0 6 0 2 4 2 12 3 8 11 3 10 12 2 8 13 3 2 12 2 8 10 2 0 14 4 0 6 0 6 3 4 14 3 8 8 2 0 14 5 0 6 0 6 3 12 14 3 8 0 4 10 12 3 8 11 3 10 13 2 8 9 3 10 12 2 8 3 2 9 12 6 9 13 2 8 12 6 0 3 0 1 11 10 4 5 15 1 0 1 11 8 5 1 11 5 6 5 15 1 0 1 11 15 6 1 11 7 7 5 15 1 0 10 2 4 15 5 8 1 11 13 7 1 11 15 7 10 2 0 14 6 0 6 0 6 3 4 14 5 8 2 4 10 11 3 8 11 3 10 10 2 8 13 3 2 10 2 0 6 0 15 2 4 15 5 8 13 2 0 12 4 0 2 0 1 11 13 7 1 11 7 6 5 15 1 0 1 11 15 4 1 11 0 4 5 15 3 0 6 3 12 14 3 8 7 4 2 14 3 8 2 4 10 14 1 8 0 4 2 14 1 8 1 2 1 9 3 8 10 2 0 14 4 0 6 0 14 1 9 8 6 8 14 1 0 15 7 0 6 0 14 1 1 11 11 0 6 0 14 1 0 12 7 0 12 0 6 3 12 13 1 10 10 2 8 14 8 0 12 0 12 1 1 9 6 0 6 0 10 2 0 13 4 0 6 0 14 1 9 12 11 0 6 0 14 1 8 13 7 0 6 0 15 2 8 10 3 0 6 0 15 2 0 11 3 0 6 0 6 3 4 15 6 9 14 1 0 14 10 0 6 0 15 2 8 12 4 0 12 0 12 1 9 13 4 8 15 2 0 11 4 0 6 0 14 1 8 12 7 0 6 0 14 1 1 7 1 8 3 2 1 11 4 0 6 0 14 1 0 10 2 0 6 0 5 2 9 12 5 8 14 1 0 13 8 0 6 0 6 3 4 12 12 9 14 1 9 14 4 8 15 2 8 13 4 0 6 0 10 2 1 10 5 0 6 0 8 2 1 7 6 0 6 0 1 2 1 15 4 8 15 2 8 13 4 0 6 0 15 2 2 11 3 8 5 2 9 10 4 0 6 0 4 3 10 6 2 8 6 3 10 4 5 8 3 2 1 13 4 8 15 2 8 14 4 0 6 0 11 3 10 11 5 8 14 1 1 15 4 0 6 0 11 3 10 8 1 8 1 2 1 12 5 8 14 1 0 11 6 0 6 0 6 3 4 11 9 9 13 3 10 13 2 8 12 1 1 15 4 8 15 2 0 12 4 0 6 0 5 4 2 12 6 8 3 2 9 7 5 8 15 2 8 13 5 0 6 0 2 4 2 6 3 8 1 2 9 10 6 0 6 0 7 4 2 9 3 8 7 1 1 15 4 8 14 1 0 11 11 0 6 0 9 4 10 9 9 8 14 1 9 14 9 0 12 0 14 1 0 13 10 0 6 0 14 1 9 9 7 0 6 0 6 3 12 14 1 10 15 2 0 14 8 0 12 0 13 3 2 14 3 8 2 4 10 12 4 8 11 3 2 15 3 0 6 0 12 1 9 13 3 8 14 1 8 13 9 0 6 0 14 1 9 12 13 0 6 0 6 3 8 13 5 0 12 0 14 1 8 10 8 0 6 0 6 3 12 14 0 10 6 3 0 15 2 0 6 0 6 3 8 13 4 0 6 0 11 3 10 13 3 8 0 4 10 11 3 8 9 3 10 12 3 0 6 0 11 3 10 13 2 8 13 3 2 14 3 8 2 4 10 13 4 8 12 1 1 14 4 8 14 1 8 12 8 0 6 0 14 1 9 13 6 8 6 3 8 13 4 0 6 0 11 3 2 14 3 8 4 3 2 14 2 8 7 3 10 6 1 0 6 0 14 1 1 11 7 8 6 3 0 14 4 0 6 0 4 3 8 13 4 0 6 0 6 3 4 14 13 9 1 2 1 14 9 8 14 1 8 13 4 0 12 0 12 1 1 14 4 8 14 1 8 14 10 0 6 0 14 1 9 12 7 8 15 2 0 13 5 0 12 0 1 2 9 11 6 8 15 2 0 14 5 0 6 0 6 3 12 14 13 0 6 0 7 1 1 14 3 8 14 1 8 12 7 0 6 0 9 3 10 11 15 8 4 3 2 11 14 8 9 1 1 15 4 8 13 2 0 12 4 0 6 0 6 3 12 13 8 8 14 1 1 10 3 8 1 2 1 9 4 8 13 2 8 8 5 0 6 0 3 2 1 12 5 8 12 1 9 12 4 8 14 1 8 14 8 0 6 0 6 3 12 14 7 9 14 1 1 14 3 0 6 0 1 2 1 12 8 8 14 1 8 13 7 0 12 0 14 1 1 6 8 8 14 1 0 10 4 0 6 0 14 1 0 10 7 0 6 0 6 3 12 14 0 10 10 2 0 12 5 0 2 1 12 1 1 15 4 8 10 2 8 13 4 0 6 0 14 1 1 12 13 0 6 0 10 2 0 14 3 0 6 0 14 1 8 11 3 0 6 0 14 1 8 11 8 0 6 0 6 3 4 13 5 9 10 2 8 14 4 0 2 1 7 1 9 13 3 8 10 2 0 14 4 0 6 0 9 1 9 13 4 0 6 0 6 3 13 14 11 8 1 3 2 14 2 8 15 2 10 12 3 8 6 3 10 12 3 8 10 2 0 14 4 0 6 0 14 1 1 12 4 0 6 0 15 2 2 14 2 8 13 2 2 13 3 8 4 3 2 13 3 8 12 1 1 14 4 8 14 1 0 11 6 0 6 0 4 3 13 14 10 8 6 3 4 14 3 9 10 2 8 12 4 0 6 0 6 3 10 12 2 8 15 2 10 13 2 8 1 3 10 13 2 8 14 1 1 15 4 0 6 0 15 2 13 15 8 8 3 2 1 13 3 8 10 2 8 13 3 0 6 0 11 3 2 14 2 8 4 3 2 14 2 8 6 3 10 13 2 8 5 2 9 10 3 0 6 0 15 2 5 10 4 8 1 2 1 15 3 8 10 2 8 13 5 0 6 0 13 2 5 15 8 8 6 3 4 14 6 8 6 3 2 14 2 8 11 3 2 13 2 8 4 3 10 13 2 8 3 2 9 15 5 0 6 0 11 3 2 13 2 8 6 3 10 12 1 8 4 3 10 10 2 8 10 2 8 13 4 0 6 0 3 2 9 14 3 0 6 0 10 2 5 15 4 8 6 3 4 14 3 8 11 3 10 13 2 8 0 4 2 11 1 8 10 2 1 14 4 0 6 0 10 2 5 14 4 8 6 3 12 12 5 8 11 3 10 13 2 8 13 3 2 13 2 8 2 4 10 11 1 8 5 2 1 15 4 8 10 2 0 14 7 0 6 0 8 2 5 15 7 8 9 3 10 14 2 8 11 3 2 15 2 8 0 4 10 13 2 8 8 2 1 12 4 0 6 0 6 3 4 15 10 8 0 4 10 14 2 8 11 3 10 13 2 8 1 4 2 13 1 8 10 2 1 13 5 8 14 1 8 12 4 8 12 1 8 5 2 0 5 0 1 15 7 0 10 5 5 15 1 0 1 3 11 4 0 8 10 2 3 2 0 8 13 3 10 11 1 8 14 1 1 15 8 8 14 1 8 13 7 0 1 0 12 2 3 5 0 0 11 0 14 1 8 7 2 0 6 0 14 1 8 12 8 0 6 0 6 3 4 15 0 9 10 2 0 14 4 0 6 0 14 1 0 11 3 0 6 0 12 1 9 10 11 8 14 1 8 12 8 0 12 0 14 1 9 12 11 8 14 1 8 11 11 0 8 1 6 3 12 13 14 8 10 2 8 14 7 0 2 1 12 1 1 11 5 8 14 1 8 10 4 0 6 0 12 1 1 12 8 8 14 1 0 12 6 0 12 0 12 1 9 10 4 8 14 1 8 13 2 0 6 0 11 1 1 10 3 8 14 1 8 13 4 0 6 0 6 3 12 14 2 9 10 2 0 14 4 0 6 0 14 1 1 14 5 8 14 1 0 12 4 0 6 0 14 1 8 12 6 0 6 0 12 1 1 13 5 0 6 0 14 1 9 13 4 8 14 1 8 12 4 0 6 0 7 1 1 15 4 8 10 2 8 14 4 0 6 0 9 1 9 14 7 0 6 0 10 2 0 14 4 0 6 0 6 3 12 14 0 9 7 1 9 13 5 0 6 0 12 1 1 10 4 8 10 2 0 14 3 0 6 0 2 1 9 12 9 0 2 0 4 8 3 0 2 8 3 0 9 8 3 0 5 15 4 0 14 1 0 11 3 0 4 0 15 2 3 5 0 0 1 0 10 2 11 6 0 8 8 2 11 5 0 0 1 0 4 3 10 10 4 8 11 3 10 11 5 8 2 1 9 13 10 8 14 1 0 12 6 0 6 0 13 3 2 13 4 8 6 3 10 13 5 0 6 0 14 1 8 10 3 0 6 0 11 3 2 13 3 8 4 3 2 12 4 8 2 1 9 13 6 8 14 1 0 12 6 0 6 0 6 3 4 14 7 9 6 3 2 12 5 8 13 3 2 15 5 8 10 2 8 13 5 0 6 0 14 1 0 9 3 0 6 0 0 4 10 11 7 8 9 3 10 13 7 8 14 1 9 15 5 8 14 1 8 13 7 0 12 0 14 1 8 11 11 0 12 0 11 3 10 10 7 8 4 3 10 11 6 8 2 1 1 13 3 0 6 0 2 1 9 12 5 8 10 2 0 13 4 8 1 3 8 13 4 0 6 0 6 3 12 13 6 9 14 1 9 15 6 0 6 0 13 3 10 14 5 8 6 3 2 12 5 8 10 2 0 13 4 8 1 3 8 13 5 0 12 0 15 0 13 9 4 8 11 3 10 10 2 8 4 3 10 9 3 8 2 1 9 13 4 8 14 1 8 13 3 0 6 0 15 0 5 10 9 8 13 3 10 13 4 8 6 3 2 14 6 8 14 1 9 12 6 8 14 1 8 12 5 0 12 0 6 3 2 14 5 8 13 3 2 14 6 8 3 2 1 10 3 8 14 1 8 11 2 0 6 0 14 1 1 14 4 8 14 1 8 12 5 0 6 0 6 3 4 14 8 9 10 2 8 12 5 0 6 0 3 2 1 14 2 0 12 0 12 1 9 14 4 8 10 2 0 12 3 0 6 0 11 3 10 13 4 8 0 4 10 12 4 8 1 2 9 10 2 8 14 1 0 14 2 0 6 0 13 3 2 14 3 8 2 4 2 14 4 8 1 2 1 6 4 8 14 1 0 14 3 8 10 2 8 14 3 0 6 0 0 4 10 11 3 8 11 3 2 13 4 8 14 1 8 13 2 0 6 0 13 3 2 14 5 8 2 4 10 14 5 8 14 1 0 13 3 8 10 2 8 14 3 0 6 0 6 3 4 14 6 9 7 1 1 14 6 8 14 1 0 12 2 0 6 0 11 3 2 14 4 8 0 4 2 14 4 8 14 1 9 5 2 8 14 1 0 13 3 8 10 2 8 14 3 0 2 0 0 8 3 0 5 15 1 0 2 8 3 0 7 8 3 0 5 15 3 0 13 3 2 15 7 8 2 4 2 14 7 8 9 1 9 13 8 8 14 1 0 12 2 0 6 0 14 1 0 13 4 0 6 0 1 3 11 8 0 8 10 2 11 6 0 8 12 2 11 8 0 8 14 1 1 13 9 8 14 1 0 14 9 0 12 0 14 1 0 6 5 0 6 0 14 1 8 10 7 0 6 0 6 3 12 14 2 9 11 3 2 13 6 8 6 3 2 14 7 8 4 3 2 14 4 8 10 2 0 14 4 0 6 0 14 1 8 5 2 0 6 0 12 1 1 15 9 8 14 1 0 11 4 0 12 0 14 1 1 11 5 8 14 1 0 11 11 0 2 1 4 3 8 12 4 0 6 0 6 3 4 14 10 9 11 3 8 11 1 0 6 0 9 3 8 14 4 0 6 0 4 3 0 13 3 0 6 0 12 1 1 14 4 0 6 0 14 1 1 15 6 8 14 1 0 10 4 0 6 0 14 1 0 11 7 0 6 0 14 1 1 14 6 8 14 1 0 11 14 0 12 0 6 3 4 13 9 9 14 1 1 14 7 8 8 2 8 13 5 0 12 0 12 1 9 8 3 8 14 1 8 5 1 0 6 0 14 1 9 14 6 8 14 1 0 11 9 0 12 0 6 3 12 12 10 8 14 1 9 14 5 8 14 1 0 13 5 0 6 0 3 2 9 14 3 0 6 0 14 1 1 12 2 8 14 1 8 10 6 0 6 0 6 3 4 14 4 8 12 1 9 14 5 8 8 2 0 9 4 0 6 0 6 3 12 12 6 8 5 2 1 8 5 0 6 0 9 8 3 0 4 8 3 0 5 15 1 0 2 8 3 0 5 15 5 0 6 3 4 14 8 8 3 2 1 14 4 8 14 1 9 13 4 8 8 2 8 11 5 0 5 0 15 2 3 10 3 5 1 0 8 2 3 7 4 5 1 0 10 2 3 10 2 5 5 0 14 1 9 12 8 8 8 2 0 14 5 0 6 0 14 1 0 12 3 0 6 0 14 1 8 12 7 0 6 0 6 3 12 14 8 10 10 2 8 13 5 0 12 0 12 1 9 13 7 8 14 1 0 12 9 0 12 0 14 1 1 14 9 8 10 2 8 14 5 0 12 0 10 2 0 14 5 0 6 0 14 1 8 11 2 0 6 0 6 3 12 10 11 8 14 1 0 13 7 0 6 0 10 2 8 14 5 0 12 0 12 1 9 13 3 8 10 2 8 14 5 0 4 0 13 2 11 5 0 2 1 0 8 2 3 7 0 10 6 2 11 5 15 1 1 0 14 1 9 14 6 0 6 0 11 3 12 14 9 8 10 2 0 14 4 0 6 0 11 3 2 9 2 8 2 4 10 10 3 8 13 3 2 11 3 8 14 1 9 11 3 0 6 0 14 1 1 15 7 8 14 1 8 14 5 0 6 0 6 3 12 13 3 8 8 2 0 12 4 0 6 0 6 3 12 12 5 8 11 3 10 13 3 8 9 3 10 10 2 8 0 4 2 9 2 8 14 1 1 11 2 8 8 2 8 12 5 0 6 0 14 1 1 15 4 8 14 1 0 13 5 0 6 0 4 3 12 14 5 8 8 2 8 12 3 0 4 0 12 2 3 6 6 10 5 2 11 2 7 2 1 0 7 2 3 6 6 2 1 0 6 3 2 14 1 8 4 3 2 13 1 8 11 3 10 10 1 8 8 2 0 13 5 0 6 0 11 3 2 14 3 8 6 3 2 15 3 8 4 3 10 13 1 8 14 1 8 12 10 0 6 0 15 2 12 13 6 8 7 1 9 12 3 8 8 2 8 12 3 0 6 0 1 3 10 11 2 8 6 3 2 13 2 8 15 2 10 11 2 8 14 1 1 12 4 0 6 0 15 2 4 14 3 8 15 2 10 13 2 8 13 2 2 12 2 8 4 3 10 11 2 8 9 1 9 13 3 8 8 2 8 12 6 0 6 0 15 2 12 13 4 8 7 1 9 13 3 0 6 0 15 2 13 11 4 8 4 3 2 12 2 8 15 2 2 9 1 8 1 3 8 12 6 0 6 0 15 2 13 12 11 8 15 2 10 13 2 8 1 3 2 13 2 8 4 3 2 13 1 8 12 1 9 9 3 0 4 0 10 2 11 5 0 0 1 0 5 2 11 9 0 8 3 2 11 7 0 0 1 0 2 1 1 13 7 8 14 1 8 13 7 0 12 0 14 1 1 11 3 0 6 0 13 3 8 13 5 0 6 0 6 3 12 13 7 9 14 1 9 14 5 0 6 0 14 1 1 13 2 8 14 1 8 12 8 0 6 0 15 2 0 12 3 0 6 0 7 1 9 15 4 0 6 0 14 1 1 14 4 8 15 2 0 12 3 0 12 0 14 1 1 14 3 8 14 1 8 13 6 0 6 0 14 1 1 14 3 8 10 2 0 11 4 0 6 0 6 3 4 14 7 1 6 0 7 1 9 13 3 0 6 0 11 3 2 12 2 8 13 3 10 13 2 8 2 4 2 10 2 8 14 1 1 15 3 0 6 0 4 3 2 14 2 8 6 3 2 14 2 8 14 1 0 14 7 0 6 0 14 1 9 14 7 8 4 3 8 13 4 0 6 0 2 4 10 11 2 8 13 3 2 12 1 8 11 3 2 11 1 0 6 0 11 3 2 15 1 8 14 1 9 14 4 8 13 3 0 10 5 0 6 0 14 1 1 13 3 0 6 0 6 3 4 12 9 9 13 3 2 15 1 8 12 1 1 13 3 0 6 0 0 4 2 6 2 8 2 4 2 5 1 8 7 4 2 5 1 8 14 1 1 14 4 8 9 3 0 14 4 0 6 0 7 4 2 13 2 8 2 4 2 13 1 8 0 4 2 11 1 8 14 1 9 11 1 0 6 0 14 1 1 15 5 8 14 1 8 14 7 0 6 0 2 4 10 13 1 8 15 2 8 13 4 0 6 0 1 2 9 13 4 0 6 0 9 4 2 10 2 8 1 2 9 10 1 8 4 3 0 14 3 0 6 0 2 4 10 14 1 8 15 2 0 13 4 0 6 0 6 3 4 14 5 9 3 2 1 9 9 1 6 0 9 4 10 13 1 8 5 4 10 13 1 8 14 1 0 14 9 0 6 0 13 3 10 14 1 8 10 2 8 11 3 0 2 0 13 7 3 0 11 7 3 0 2 8 3 0 5 15 7 0 5 2 3 6 0 8 3 2 11 4 0 8 10 2 3 6 0 0 3 0 2 4 2 14 1 8 0 4 10 10 2 8 7 4 10 6 1 8 15 2 8 4 1 0 12 0 11 3 10 14 1 8 14 1 1 14 4 8 15 2 0 14 4 0 6 0 1 2 1 7 2 0 6 0 6 3 12 11 13 9 2 4 2 11 2 8 3 2 1 12 3 8 14 1 8 14 8 0 6 0 11 3 2 15 3 8 12 1 1 14 3 8 1 3 0 14 3 0 6 0 14 1 1 14 3 0 6 0 13 3 2 11 1 8 1 2 9 6 1 0 6 0 3 2 9 12 2 8 14 1 0 14 9 0 6 0 6 3 10 12 1 8 9 1 1 15 3 0 6 0 9 3 2 14 1 8 14 1 9 6 2 8 6 3 8 14 3 0 6 0 11 3 2 15 1 8 12 1 9 14 2 0 6 0 6 3 4 14 10 9 4 3 10 11 1 8 14 1 1 12 4 0 6 0 4 3 2 14 2 8 7 1 1 14 2 8 14 1 8 13 13 0 6 0 15 2 2 14 1 8 12 1 1 13 2 8 4 3 8 11 4 0 6 0 9 1 1 14 3 0 6 0 6 3 2 14 3 8 12 1 9 12 4 8 11 3 0 13 3 8 12 3 8 10 3 0 6 0 1 3 5 12 6 8 5 1 1 14 2 0 6 0 15 2 5 7 15 8 4 3 10 13 2 8 6 3 10 13 2 8 11 3 2 13 2 8 7 1 1 15 3 8 14 1 0 11 6 0 6 0 12 1 9 10 3 8 15 2 8 10 6 0 6 0 10 2 5 15 11 8 6 3 4 11 2 10 2 1 1 4 1 0 6 0 4 3 10 14 1 8 6 3 2 14 1 8 11 3 2 13 2 8 9 1 9 13 3 8 1 3 8 11 5 0 6 0 2 1 1 14 4 8 14 1 0 14 12 0 6 0 8 2 5 14 7 8 7 1 1 14 3 0 6 0 4 3 2 14 2 8 11 3 2 13 3 8 6 3 2 14 1 8 0 1 9 13 5 8 10 2 0 8 4 0 6 0 15 2 5 13 5 8 7 1 9 12 3 0 6 0 3 2 13 14 2 8 13 2 0 12 4 0 6 0 3 2 13 15 5 8 11 3 2 13 2 8 4 3 2 14 2 8 6 3 10 14 2 8 7 1 1 15 4 8 10 2 8 11 3 0 6 0 6 3 4 13 4 8 14 1 9 10 4 8 14 1 8 11 10 0 2 0 11 7 3 0 5 15 1 0 13 7 3 0 5 15 2 0 2 8 3 0 5 15 1 0 10 2 13 13 5 8 6 3 12 12 7 8 11 3 10 14 2 8 6 3 10 15 1 8 4 3 10 14 2 8 14 1 9 11 6 8 13 2 8 8 5 0 6 0 14 1 13 15 10 0 6 0 6 3 4 14 6 8 11 3 10 12 2 8 4 3 10 14 1 8 6 3 10 13 1 8 12 1 9 14 6 0 3 0 1 3 3 6 12 5 2 0 10 2 3 2 11 5 1 0 12 2 3 6 9 13 14 1 1 14 7 8 14 1 0 14 6 0 12 0 14 1 0 11 4 0 6 0 14 1 8 11 7 0 6 0 6 3 12 13 5 9 10 2 8 12 4 0 12 0 12 1 9 12 8 8 10 2 0 6 2 0 6 0 10 2 0 14 5 0 6 0 14 1 9 14 7 0 6 0 10 2 0 14 4 0 2 1 6 3 4 14 5 9 14 1 0 12 11 0 6 0 13 2 2 12 2 8 6 3 2 12 3 8 2 3 10 9 2 0 12 0 6 3 2 14 4 8 1 3 10 13 3 8 12 2 2 13 2 8 3 2 1 15 5 8 14 1 0 12 3 0 6 0 10 2 3 7 0 13 15 2 3 7 1 13 8 2 11 6 15 12 14 1 8 11 7 0 6 0 8 2 1 15 4 0 6 0 14 1 8 5 2 0 6 0 14 1 9 13 2 8 14 1 8 12 8 0 6 0 6 3 12 14 8 9 9 3 10 13 2 8 2 4 2 13 3 8 13 3 2 10 1 8 10 2 8 13 4 0 12 0 3 2 1 15 4 0 6 0 10 2 0 14 5 0 6 0 5 2 9 13 3 0 6 0 10 2 8 13 4 0 6 0 4 3 2 13 2 10 9 3 2 13 3 10 15 2 10 13 1 10 1 2 9 10 3 0 6 0 3 2 1 14 5 0 6 0 6 3 4 14 6 1 6 0 1 2 1 14 3 0 12 0 14 1 9 12 8 8 14 1 8 9 4 0 4 0 10 2 11 5 10 10 1 3 3 4 7 10 12 2 11 6 9 2 2 0 14 1 8 12 8 0 12 0 14 1 8 5 2 0 6 0 14 1 8 10 7 0 6 0 6 3 4 12 12 9 10 2 0 13 5 0 12 0 12 1 1 13 5 0 6 0 10 2 0 15 4 0 5 0 15 2 3 6 5 2 1 0 10 2 11 6 3 10 8 2 3 4 5 10 14 1 9 14 9 0 6 0 10 2 8 14 4 0 2 1 6 3 4 10 7 1 2 1 15 2 10 13 4 8 4 3 10 13 5 8 9 3 10 12 5 0 6 0 14 1 0 15 3 0 1 0 8 2 3 8 14 9 13 2 11 6 13 9 6 2 11 6 15 1 5 0 4 3 2 14 6 8 15 2 10 13 4 8 9 3 2 13 5 8 14 1 0 14 3 0 6 0 6 3 12 12 11 8 3 2 1 14 3 8 14 1 0 13 3 0 6 0 10 2 9 12 4 8 8 2 1 14 3 8 14 1 0 12 3 0 6 0 13 2 10 10 11 10 6 3 2 12 10 10 2 3 10 10 10 10 5 2 1 15 5 8 14 1 0 14 3 0 6 0 6 3 4 10 10 8 14 1 0 12 2 0 6 0 1 2 9 12 2 8 14 1 0 12 2 0 6 0 5 2 9 10 3 8 3 2 1 12 4 8 14 1 0 12 3 0 5 0 5 2 11 6 7 10 12 2 3 9 4 10 7 2 11 6 6 2 1 0 6 3 4 13 4 8 14 1 1 15 5 8 14 1 0 14 3 8 15 2 8 12 3 8 10 2 8 11 2 0 6 0 6 3 12 11 6 8 14 1 8 14 3 8 10 2 0 13 3 8 15 2 0 12 3 0 6 0 12 1 9 14 4 8 14 1 0 12 2 8 15 2 8 11 3 8 10 2 0 10 2 0 6 0 6 3 4 14 4 8 3 2 9 8 2 8 1 2 1 11 3 8 14 1 8 12 3 8 10 2 0 10 2 8 15 2 8 10 2 0 6 0 6 3 2 12 4 9 13 2 2 12 4 9 1 3 2 10 5 9 7 1 1 14 3 8 14 1 8 12 2 8 15 2 8 9 4 8 10 2 0 8 3 0 6 0 6 3 4 14 6 8 14 1 8 11 2 8 15 2 0 13 3 8 10 2 8 12 3 0 6 0 15 2 13 14 3 8 10 2 5 15 3 8 12 1 1 13 3 8 14 1 0 11 3 8 15 2 0 13 3 8 10 2 8 13 3 0 6 0 15 2 5 15 3 8 10 2 13 15 4 8 6 3 4 14 4 8 7 1 1 14 3 8 14 1 0 13 2 8 15 2 0 11 3 8 10 2 0 11 3 0 4 0 10 2 3 10 15 0 1 0 5 2 11 9 13 8 3 2 11 8 13 8 1 15 0 0 0 0 5 15 1 0 6 3 2 14 5 8 12 2 10 12 2 8 1 3 2 14 3 8 14 1 1 14 5 8 14 1 8 12 4 0 12 0 14 1 1 14 4 8 14 1 8 13 3 0 12 0 6 3 4 14 12 8 10 2 8 13 4 0 6 0 12 1 1 14 6 0 12 0 10 2 8 14 4 0 6 0 14 1 9 13 6 0 6 0 10 2 8 13 3 0 12 0 14 1 9 13 4 8 14 1 8 14 4 0 6 0 6 3 12 14 6 9 10 2 0 14 3 0 6 0 10 2 0 14 4 0 6 0 15 2 2 13 2 8 4 3 10 12 3 8 9 3 2 13 4 8 14 1 8 11 6 0 6 0 15 2 10 11 4 8 9 3 2 11 5 8 4 3 10 12 4 8 12 1 9 13 6 8 10 2 0 14 4 0 6 0 14 1 1 14 6 8 14 1 8 14 6 0 6 0 15 2 2 14 3 8 4 3 2 14 3 8 9 3 10 13 4 0 6 0 14 1 9 13 5 8 14 1 8 12 8 0 12 0 6 3 12 3 11 8 14 1 9 13 5 8 10 2 0 14 5 0 6 0 7 1 1 9 6 0 12 0 9 1 1 14 8 8 10 2 8 14 4 0 12 0 5 1 1 13 8 8 10 2 8 14 4 0 6 0 15 2 5 15 8 8 11 3 12 14 3 0 6 0 11 3 12 12 6 8 7 1 9 13 13 8 14 1 8 12 7 0 6 0 15 2 13 15 6 8 0 4 10 14 14 8 5 4 10 13 13 8 11 3 2 15 14 8 10 2 8 13 2 0 6 0 6 3 13 14 8 8 11 3 12 14 6 8 10 2 8 13 3 0 6 0 5 1 1 1 14 8 14 1 0 11 6 0 6 0 6 3 12 10 3 8 10 2 8 14 3 0 6 0 6 3 4 12 0 9 2 1 1 13 11 8 14 1 0 12 6 0 12 0 14 1 0 10 9 0 6 0 14 1 1 15 7 0 6 0 6 3 12 12 1 10 9 3 2 14 11 8 4 3 2 14 9 8 15 2 10 14 4 8 10 2 8 14 5 0 2 1 2 1 9 12 4 8 10 2 8 14 3 0 6 0 2 1 1 13 7 0 6 0 10 2 0 15 3 0 6 0 2 1 9 11 2 1 6 0 14 1 8 13 8 0 6 0 6 3 12 14 6 9 4 3 10 13 14 8 9 3 2 12 0 9 15 2 2 14 13 8 10 2 0 15 3 0 6 0 14 1 1 15 5 8 10 2 8 13 3 0 6 0 14 1 0 11 7 0 6 0 2 1 9 12 12 8 10 2 8 14 4 0 6 0 14 1 0 11 8 0 12 0 9 3 10 12 7 8 15 2 2 13 3 8 4 3 10 12 6 8 14 1 0 10 7 0 6 0 2 1 9 12 5 0 6 0 6 3 12 13 5 10 14 1 1 15 6 8 10 2 8 14 5 0 6 0 9 3 10 12 6 8 15 2 10 12 4 8 4 3 10 11 5 0 12 0 2 1 9 11 4 8 10 2 0 13 4 0 6 0 4 3 10 13 4 8 9 3 10 12 5 8 15 2 10 13 3 8 2 1 9 12 7 0 6 0 15 2 13 14 11 8 10 2 8 13 3 0 6 0 15 2 2 11 4 8 9 3 2 13 5 8 4 3 10 10 6 8 2 1 9 13 9 8 3 2 8 13 2 0 6 0 5 2 8 14 4 0 6 0 6 3 13 14 4 8 6 3 4 14 12 8 6 3 10 11 3 9 1 3 10 10 0 9 13 2 10 12 0 1 6 0 6 3 5 14 4 8 12 1 1 13 4 8 10 2 0 14 5 0 12 0 6 3 13 15 4 8 6 3 4 14 15 8 2 1 9 12 9 8 3 2 0 14 2 0 6 0 14 1 8 14 4 8 13 1 8 8 3 0 12 0 11 3 2 11 3 8 14 1 8 12 5 0 6 0 13 3 10 14 3 8 2 1 1 12 5 0 6 0 6 3 12 13 15 9 14 1 9 13 6 8 10 2 8 14 4 0 6 0 11 3 2 14 3 0 6 0 13 3 10 10 4 0 6 0 2 1 1 10 5 8 10 2 0 14 3 0 6 0 11 3 2 15 3 8 2 1 9 12 7 0 6 0 13 3 2 12 3 8 10 2 8 14 4 0 6 0 2 1 1 12 15 0 6 0 11 3 2 15 3 8 14 1 8 13 6 0 6 0 15 2 13 15 13 8 15 2 12 13 9 8 13 3 2 12 3 8 10 2 0 14 2 0 6 0 12 1 9 14 5 8 10 2 0 14 4 0 6 0 15 2 12 11 3 8 14 1 8 11 7 0 6 0 15 2 4 12 5 8 2 1 1 11 7 8 10 2 0 14 4 0 6 0 14 1 0 14 3 0 6 0 14 1 0 12 3 0 6 0 4 3 10 11 6 8 11 3 2 13 5 8 14 1 0 12 3 0 6 0 13 3 2 11 3 8 6 3 10 13 3 8 2 1 9 11 6 8 14 1 8 12 6 0 6 0 6 3 12 14 14 8 14 1 9 13 8 8 10 2 0 14 4 0 6 0 11 3 2 13 2 8 4 3 10 11 4 0 6 0 13 3 10 13 4 8 6 3 2 14 5 8 2 1 1 11 4 8 14 1 0 13 5 0 6 0 10 2 0 14 3 0 12 0 10 2 8 13 4 0 6 0 3 2 4 15 3 8 9 3 2 12 6 8 0 4 10 11 5 8 3 2 1 15 4 8 14 1 0 11 4 0 6 0 3 2 12 12 4 8 2 4 10 10 4 8 11 3 10 13 5 8 5 2 1 14 5 8 10 2 8 12 4 0 6 0 1 2 9 13 4 8 14 1 0 7 1 0 6 0 3 2 12 14 4 8 0 4 10 11 5 8 9 3 2 11 5 8 3 2 9 12 9 8 14 1 0 13 4 0 6 0 11 3 10 10 6 8 2 4 2 11 6 8 14 1 0 11 7 0 6 0 2 1 1 13 8 0 6 0 14 1 0 14 6 0 12 0 14 1 8 10 3 0 6 0 2 1 9 11 6 8 14 1 0 11 5 0 6 0 15 2 5 15 15 8 6 3 4 14 7 9 4 3 2 13 7 11 15 2 2 14 6 11 9 3 10 13 7 11 14 1 9 14 6 8 15 2 8 11 6 0 6 0 14 1 0 11 3 0 6 0 2 1 9 11 6 8 14 1 0 13 6 0 12 0 2 1 9 11 11 8 14 1 8 14 6 0 2 1 2 1 1 11 7 8 7 1 0 15 4 0 6 0 6 3 4 14 6 9 2 11 14 3 2 11 6 3 5 15 1 0 2 11 13 2 2 11 5 2 5 15 1 0 2 11 12 1 5 15 1 0 2 11 4 1 2 11 11 0 5 15 1 0 2 11 4 0 2 11 0 0 5 15 2 0 15 2 8 7 5 0 3 0 2 11 15 1 5 15 1 0 2 11 15 3 2 11 0 4 5 15 2 0 12 1 1 14 5 0 6 0 2 1 9 11 9 0 6 0 14 1 0 15 4 0 12 0 6 3 12 14 12 8 14 1 8 11 3 0 6 0 2 1 9 12 5 8 14 1 0 13 3 0 6 0 14 1 9 13 5 0 6 0 6 3 12 13 11 8 15 2 8 12 5 0 6 0 2 1 1 11 5 0 6 0 14 1 0 14 4 0 6 0 6 3 4 14 4 8 2 1 1 12 7 8 15 2 0 14 3 0 6 0 6 3 4 10 6 8 15 2 0 12 3 0 6 0 14 1 8 9 4 0 6 0 6 3 12 13 3 8 2 1 1 12 5 8 14 1 8 11 7 0 6 0 15 2 13 14 6 8 6 3 12 11 7 8 15 2 8 13 5 0 6 0 6 3 13 14 6 8 12 1 9 14 4 8 14 1 8 9 3 0 6 0 4 3 5 14 7 8 6 3 12 10 3 8 14 1 0 12 5 0 6 0 6 3 4 12 7 8 2 1 9 11 3 0 4 0 1 3 11 3 9 13 10 2 3 2 9 5 1 0 12 2 3 4 6 5 1 0 2 1 9 13 6 8 14 1 8 14 4 0 12 0 6 3 10 14 1 8 14 1 8 13 3 0 6 0 11 3 2 15 2 8 2 1 9 10 5 8 14 1 8 12 3 0 6 0 6 3 4 14 4 9 14 1 9 14 5 8 15 2 8 13 4 0 6 0 6 3 2 14 1 8 14 1 8 12 2 0 6 0 11 3 10 14 2 8 2 1 1 11 5 8 14 1 8 11 4 0 12 0 6 3 10 13 1 8 2 1 9 13 7 8 14 1 0 14 4 0 6 0 11 3 10 14 2 0 12 0 6 3 10 14 1 8 2 1 9 9 4 0 6 0 6 3 4 14 5 9 11 3 2 15 2 8 12 1 9 13 6 8 15 2 0 14 8 0 2 1 7 1 1 14 4 0 2 0 10 2 11 10 9 13 15 2 11 7 9 5 1 0 8 2 11 7 6 5 3 0 10 2 0 8 2 0 6 0 7 1 9 10 3 8 1 3 8 11 5 8 15 2 0 13 5 0 6 0 6 3 2 15 3 8 11 3 2 14 3 8 4 3 10 14 3 8 9 1 9 14 6 8 10 2 8 14 4 0 12 0 6 3 4 10 9 9 5 1 1 13 4 8 10 2 8 13 3 0 6 0 7 1 9 14 4 8 1 3 0 14 4 8 15 2 0 15 4 0 6 0 10 2 8 14 4 0 6 0 7 1 1 13 4 0 6 0 10 2 8 12 4 0 6 0 9 1 1 12 7 8 1 3 0 13 4 8 15 2 8 14 4 0 6 0 10 2 8 14 4 0 6 0 12 1 9 13 4 0 6 0 10 2 8 14 4 0 6 0 14 1 1 15 5 8 1 3 8 13 4 8 15 2 0 13 4 0 6 0 6 3 12 11 4 8 8 2 2 14 3 8 4 3 10 13 4 8 10 2 8 14 4 0 6 0 15 2 5 13 3 8 6 3 4 13 10 8 12 1 9 9 4 0 4 0 1 3 11 6 0 5 1 0 10 2 3 6 0 13 12 2 3 9 15 4 1 0 14 1 1 14 9 8 14 1 0 14 3 0 12 0 6 3 10 11 3 8 10 2 2 13 3 8 14 1 0 12 1 0 6 0 14 1 0 14 5 0 6 0 6 3 4 14 7 10 15 2 8 14 4 0 6 0 6 3 2 10 3 8 10 2 2 13 3 8 14 1 8 12 3 0 6 0 12 1 9 12 12 8 14 1 8 14 4 0 12 0 6 3 10 12 4 8 10 2 10 13 3 8 14 1 1 12 7 8 14 1 8 14 6 0 2 1 6 3 10 10 3 8 10 2 2 14 3 0 6 0 6 3 12 13 11 9 15 2 8 14 10 8 1 3 8 14 10 0 12 0 6 3 10 10 3 8 10 2 10 13 3 0 6 0 12 1 9 12 4 8 14 1 0 10 3 0 5 0 13 2 11 6 7 2 1 0 8 2 3 7 8 10 6 2 11 5 9 10 14 1 9 13 9 8 14 1 0 11 5 0 12 0 6 3 10 12 3 8 10 2 10 13 3 8 14 1 9 12 7 8 14 1 0 12 2 0 6 0 14 1 0 13 4 0 6 0 6 3 12 13 2 9 1 2 1 14 9 8 15 2 0 14 6 0 6 0 10 2 10 13 2 8 6 3 2 12 4 8 14 1 0 12 2 0 6 0 12 1 1 11 4 8 14 1 8 12 5 0 6 0 14 1 1 15 8 0 6 0 12 2 3 8 5 10 14 1 8 14 9 0 1 0 7 2 11 5 6 10 5 2 11 6 7 2 11 0 6 3 4 11 11 0 6 0 7 1 1 15 0 2 6 0 11 3 10 13 14 8 15 2 2 13 15 8 6 3 2 14 14 8 4 3 2 14 14 8 15 2 0 15 11 0 6 0 6 3 12 9 13 0 12 0 5 1 9 1 4 8 14 1 0 12 3 0 5 0 10 2 11 8 0 8 3 2 11 8 0 8 5 2 3 10 0 0 1 0 14 1 9 14 13 8 14 1 0 11 3 0 6 0 14 1 0 12 2 0 6 0 6 3 4 13 12 8 10 2 10 13 3 8 6 3 10 12 4 8 14 1 0 12 3 0 6 0 14 1 0 12 3 0 6 0 15 2 8 13 5 0 6 0 6 3 12 11 9 8 10 2 2 14 3 8 6 3 2 9 3 8 14 1 8 11 2 0 6 0 12 1 1 12 12 8 14 1 8 12 4 0 12 0 6 3 4 12 12 8 10 2 2 14 3 8 6 3 2 13 3 8 14 1 9 13 11 8 14 1 8 14 13 0 2 1 6 3 4 12 11 0 6 0 15 2 0 14 13 8 4 3 0 14 13 0 12 0 6 3 4 12 10 0 6 0 12 1 9 6 4 8 14 1 8 13 3 0 6 0 14 1 9 11 7 8 14 1 8 12 4 0 6 0 6 3 12 11 10 8 14 1 8 11 3 0 6 0 11 3 2 13 10 8 15 2 2 13 10 8 14 1 1 12 6 0 6 0 15 2 0 15 4 0 6 0 6 3 4 13 10 8 1 2 1 12 7 0 6 0 11 3 10 12 5 8 15 2 2 13 4 8 14 1 8 14 5 0 6 0 3 2 1 12 4 8 15 2 8 14 6 0 6 0 6 3 12 13 7 8 3 2 9 12 4 0 6 0 11 3 2 11 4 8 15 2 10 11 3 8 5 2 1 9 9 9 1 12 5 0 1 12 3 1 5 15 1 0 1 12 15 1 1 12 8 2 5 15 1 0 1 12 2 3 1 12 12 3 5 15 1 0 1 12 5 4 1 12 13 4 5 15 1 0 1 12 4 5 1 12 10 5 5 15 1 0 1 12 15 5 1 12 3 6 5 15 1 0 1 12 7 6 1 12 10 6 15 2 0 14 4 0 1 0 1 12 15 6 1 12 1 7 5 15 1 0 1 12 4 7 1 12 5 7 5 15 1 0 1 12 7 7 5 15 1 0 1 12 8 7 5 15 2 0 6 3 4 14 10 8 15 2 8 13 5 0 1 0 1 12 4 7 1 12 1 7 5 15 1 0 1 12 12 6 1 12 5 6 5 15 1 0 1 12 13 5 1 12 3 5 5 15 1 0 1 12 6 4 1 12 10 3 5 15 1 0 1 12 12 2 1 12 14 1 5 15 1 0 15 2 2 13 4 8 11 3 2 13 5 8 1 12 14 0 1 12 0 0 5 15 6 0 3 2 9 11 9 8 14 1 8 12 5 0 4 0 11 7 3 0 5 15 1 0 13 7 3 0 5 15 1 0 6 3 12 13 10 8 15 2 0 14 5 0 1 0 2 8 3 0 5 15 5 0 1 2 1 9 4 0 6 0 3 2 9 11 5 0 3 0 1 3 11 10 8 5 1 0 10 2 3 7 8 13 12 2 3 9 8 5 2 0 6 3 12 13 8 8 10 2 2 13 3 8 6 3 2 11 4 8 14 1 1 14 11 8 15 2 0 14 6 0 12 0 6 3 4 12 10 8 10 2 10 10 3 8 6 3 10 10 4 8 14 1 8 12 4 0 6 0 15 2 0 14 7 0 12 0 6 3 4 14 9 8 15 2 0 15 5 0 6 0 12 1 1 14 10 8 14 1 0 14 3 0 12 0 6 3 12 14 3 8 14 1 9 12 10 8 15 2 8 13 7 0 6 0 6 3 4 11 6 0 6 0 15 2 8 14 7 0 6 0 6 3 4 14 7 0 6 0 14 1 0 14 8 0 6 0 15 2 0 14 6 0 6 0 6 3 12 13 12 0 6 0 12 1 9 10 4 8 14 1 8 13 6 0 6 0 14 1 9 14 6 8 15 2 8 14 4 8 4 3 0 12 4 0 1 0 15 2 3 10 7 8 8 2 3 8 6 8 10 2 3 10 6 0 5 0 15 2 2 12 4 8 13 2 10 9 3 8 1 3 10 12 2 0 6 0 6 3 4 13 4 8 4 3 2 11 3 8 9 3 10 12 3 8 14 1 1 13 4 8 15 2 0 14 5 8 4 3 0 14 5 0 6 0 10 2 3 9 5 8 1 3 11 8 6 8 12 2 11 9 6 8 6 3 4 11 4 8 14 1 9 10 4 8 12 1 9 12 6 0 6 0 6 3 12 12 4 8 9 3 10 13 5 8 4 3 2 12 3 8 3 2 0 14 3 0 6 0 6 3 12 11 3 8 9 1 9 14 4 8 15 2 0 14 3 8 4 3 8 13 4 0 4 0 15 2 11 10 5 8 8 2 3 9 4 8 10 2 11 10 5 0 2 0 6 3 12 10 3 8 15 2 2 8 4 8 9 1 9 14 5 8 15 2 0 13 5 8 4 3 0 12 4 0 6 0 6 3 4 12 3 0 6 0 6 3 12 11 3 8 7 1 1 14 5 8 10 2 8 14 4 0 4 0 1 3 11 10 5 0 1 0 10 2 11 9 4 8 12 2 3 11 4 0 1 0 6 3 4 11 3 8 2 4 2 12 4 8 9 3 2 13 3 8 11 3 10 14 3 8 15 2 8 14 5 8 4 3 0 14 4 0 6 0 6 3 4 12 3 8 2 4 10 13 4 8 9 3 10 13 3 8 11 3 10 13 3 8 7 1 1 14 5 1 6 0 6 3 4 11 3 8 11 3 2 13 3 8 13 3 10 11 1 8 15 2 0 14 2 8 4 3 0 14 3 0 5 0 15 2 11 11 5 8 8 2 11 10 3 8 10 2 3 12 4 0 1 0 4 3 5 15 3 8 6 3 12 11 3 8 7 4 2 13 3 8 0 4 2 13 3 8 2 4 10 13 3 8 15 2 0 13 8 8 4 3 0 13 8 0 6 0 4 3 5 15 5 8 6 3 4 11 3 8 0 4 10 11 2 0 6 0 6 3 4 11 3 8 7 1 9 6 3 8 9 1 9 5 7 0 5 0 1 3 11 11 7 8 10 2 11 10 4 8 12 2 3 12 6 0 1 0 6 3 12 11 3 8 9 4 10 14 3 8 7 4 10 14 3 0 5 0 3 15 247

Always nice to meet people working with older synthesizers, I recently revised an old Roland RD250 digital piano as my midi keyboard (I like the old fashioned heavy and piano-feel key mechanism) and also revised a Roland Juno 106 lately which had a dead voice chip.

You’re more than welcome.

I wasn’t aware that performance was important. When you want to speed things up in AppleScript, code becomes everything but obvious, so I thought I post a clean small script. Here an optimized version even if the code is less obvious. Took now one second on my machine.

on byteStrings2HexStrings(byteStrings)
	set hexValues to {}
	script o
		property hexChars : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
		property byteStrings : {}
		property hexStrings : {}
	end script
	
	set o's byteStrings to words of byteStrings
	
	repeat with i from 1 to count o's byteStrings
		set byteValue to item i of o's byteStrings as integer
		set hexString to item (byteValue div 16 + 1) of o's hexChars & item (byteValue mod 16 + 1) of o's hexChars
		set end of o's hexStrings to hexString
	end repeat
	
	set oldTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to space
	set hexStrings to o's hexStrings as string
	set AppleScript's text item delimiters to oldTIDs
	return hexStrings
end byteStrings2HexStrings

When lists getting bigger than 10k items I would suggest moving to a shell, it has a built in function named printf which can print a value in another presentation:

on byteStrings2HexStrings(byteStrings)
	set value to do shell script "while read line; do
	for word in $line; do
    		printf '%02X ' \"$word\"
	done
done <<< " & quoted form of byteStrings & "
"
	return text 1 thru -2 of value
end byteStrings2HexStrings

The difference is that the first script is faster when using smaller lists and the latter (like McUsr’s example) will be faster when using bigger lists (strings of decimal values).

Hello.

Here is a pretty fast solution, given that you aren’t on OS9 when performing the conversion to hex. :slight_smile:


set decnumbers to "240 15  1 14 1 8 11 9 0 6 0 6 3 12 12 4 2 12 0 14 1 0 11 3 0 6 0"
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set decnumbers to text items of decnumbers
set AppleScript's text item delimiters to linefeed
set decnumbers to decnumbers as text
set AppleScript's text item delimiters to tids
set hexnumbers to paragraphs 1 thru -2 of (do shell script "( echo \"obase=16\" ;  echo " & quoted form of decnumbers & "  )| bc  |xargs printf '%02s
'" without altering line endings)
set hexnumbers to items of hexnumbers
set AppleScript's text item delimiters to space
set hexnumbers to hexnumbers as text
set AppleScript's text item delimiters to tids
return hexnumbers


Edit
I made it snappier. And I removed a typo.

Small typo there.

It seems that there is a small error in McUsr’s script.
He save the current delimiter after setting it to “”.
I assume that it would be better to save it on entry.

# set AppleScript's text item delimiters to "" # DISABLED
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set decnumbers to "240 15  1 14 1 8 11 9 0 6 0 6 3 12 12 4 2 12 0 14 1 0 11 3 0 6 0"
# set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space} # MOVED
set decnumbers to text items of decnumbers
set AppleScript's text item delimiters to linefeed
set decnumbers to decnumbers as text
set AppleScript's text item delimiters to "" # EDITED
set hexnumbers to do shell script "( echo \"obase=16\" ;  echo " & quoted form of decnumbers & "  )| bc  |xargs printf '%02s
'" without altering line endings
set AppleScript's text item delimiters to linefeed
set hexnumbers to text items of hexnumbers
set AppleScript's text item delimiters to space
set hexnumbers to hexnumbers as text
set AppleScript's text item delimiters to tids
return hexnumbers

Yvan KOENIG (VALLAURIS, France) jeudi 5 mars 2015 11:55:41

Hello.

First a copy/paste error, I didn’t get the s within the area to paste over.

And yes, Yvan is right, I had to put it inside, as I broke the script at a time, in the middle of some operation involving text item delimiters. Both issues will be fixed almost as soon as you have read this. :slight_smile:

Hi Guys.

DJ’s shell script omits the last number of the input unless it’s followed by a space.

McUsrII’s adds a space to the end of the output.

Hello Nigel.

I have removed the space in post #6, which resulted from the last linefeed sent from the do shell script, so now it should be all good and well for my part, but I realize that the format of the ouput really depends on how the OP, would like to continue processing the hexnumbers.

correct, because every number is followed by a space, including the last one.

Where does it say that?

nvm… updated my post so the string always ends with an space.

edit: I’ve updated it to a less format sensitive handler. Even other whitespaces (like linefeed), double whitespaces, leading and trailing spaces are all supported now.

Once again MANY thanks to all of you for these modifications–I’m impressed not only by your technical skills but by your collective generosity. It makes me feel like there’s something really right in the world…
Andrew

Both scripts presented here work correctly up to numbers ≤ 256. For numbers greater than 256, the script from @DJ Bazzie Wazzie throws an error. @McUsrII’s script gives the correct value, but does not always add the required 0.

For example, the decimal number 1300 should have the hexadecimal representation “0514”, not “514” (result of @McUsrII’s script, and, as I sad, @DJ Bazzie Wazzie’s script throws error for 1300.)

I undertook to tweak the script of @DJ Bazzie Wazzie. Here is tweaked script:


set hexChars to "0123456789ABCDEF"
set midiStream to "5020000 15 2 0 7 4 1300 4 1 247 240"

set hexValues to ""
repeat with byteString in words of midiStream
	set byteValue to byteString as integer
	set {aNum, n} to {"", byteValue}
	repeat
		set aNum to (item (n mod 16 + 1) of my hexChars) & aNum
		set n to n div 16
		if (n is 0) then exit repeat
	end repeat
	if ((count aNum) mod 2) = 1 then set aNum to "0" & aNum
	set hexValues to hexValues & aNum & space
end repeat

set hexValues to text 1 thru -2 of hexValues

This seems like a problem for the shell to solve.

set hexs to do shell script "printf '%02X ' " & "240 15 2 0 7 4 13 4 1 247 240"

→ "F0 0F 02 00 07 04 0D 04 01 F7 F0 "

The actual terminal command is:

A quick breakdown of the printf command:
% indicates that what follows determines the output format
0 pad with zero
2 pad to 2 digits
X hexadecimal in upper case (‘x’ would generate lowercase letters)
’ ’ The trailing space inside the quotes appends a space to each number. If you exclude that, you get a solid stream of 2-digit hex numbers and the quotes become optional.

As always, ‘man printf’ will provide the command’s man page.

To work with a string from a file (e.g. the long string from post #4) you could do something like this:

set hexs to do shell script "printf '%02X ' " & (read alias (((path to desktop) as text) & "dechex.txt"))

→ "F0 0F 02 00 07 0A 08 06 01 F7 F0 0F 02 00 08 06 01 0A 08 00 00 00 03 0D 01 00 00 00 00 0A 00 0F 05 06 07 02 0B 0E 07 08 00 00 07 0E 07 00 03 00 07 08 07 0E 03 00 07 0A 06 02 07 01 0B 0E 07 07 02 00 0F 0E 07 0F 0F 00 0C …

Deposited into a file, its size would be ~35kb, and it would contain 11556 numbers, which matches the long decimal string.