converting binary to ASCII decimal data list on Mac OSX

Personally I use it to include already compiled assembler binary data or to convert i.e. small portion of bitmap like sprite or tiles to simple ASCII source to be included as DEF… or DATA… either in Assembler or BASIC source.

Above 32x32pixels graphics – to do it just in binary it’s simple but time consuming. 01000000, 00111111, 11100000, 00001111 – this is binary for just first row of above graphics.

On ZX Spectrum BASIC (or text file to be coverted by zmakebas) you need to write it down as 999 DATA BIN 01000000, BIN 00111111, BIN 11100000, BIN 00001111 then in loop of FOR… READ… POKE… NEXT… commands. So to be honest – it’s easy to do by pen on paper, but time consuming to write it down without stupid mistakes in data. And we have computers, you know, to simply stuff like that. So let’s them working.

How to do it with Mac OSX? Of course we need AppleScript.

Let’s do it with converting graphics, in our example 32×32 pixels, monochrome. I will be using Photoshop, pretty old version as CS5.1 but you can easy find relevant options in other software to replicate my moves.

To convert to bitmap (so zero-one data – no colour, no grayscale) it needs to be 8bit (just tip if you convert from 16bit and stuck with greyed bitmap mode in Photoshop).

step 1: save as .pbm

step 2: use my read pbm and extract raw data.scpt Applescript. Adobe Photoshop saves not fully text version of .pbm as described around in the internet. First 9 bytes are text – in our example:


Three tags, between all of them we have $0A handler. One important to note – we have 32×32 bitmap and… bingo – it’s noted in the header, right?

So we can ommit first 9 bytes (as in my Applescript code) and read the rest.

step 3: select and copy everything between { }

step 4: paste do your editor (BBEdit in my example) add code (BASIC or Assembler) and you have it. 30 seconds max 🙂

I will be sharing here more simple code and workflow solutions so – until next time.

Let me know if it works for you, or if you have a problem using this. Cheers!