This is part of my bitwise autotiler. I havent used bitwise or counted in bits before so it’s not perfect.
This is inside of a loop that checks every tile.
Tile temp;
				if (cleanMap[w - 1][h - 1] == 1)		temp.corner += 8;
				if (cleanMap[w - 1][h] == 1)			temp.side += 128;
				if (cleanMap[w - 1][h + 1] == 1)		temp.corner += 4;
				if (cleanMap[w][h - 1] == 1)			temp.side += 16;
				if (cleanMap[w][h + 1] == 1)			temp.side += 64;
				if (cleanMap[w + 1][h - 1] == 1)		temp.corner += 1;
				if (cleanMap[w + 1][h] == 1)			temp.side += 32;
				if (cleanMap[w + 1][h + 1] == 1)		temp.corner += 2;
				tilemap[w][h] = temp;
Corner and Side är chars that holds the values for the sides and corners.  It checks all 8 directions and adds them. But you can use one char for this, as i said, i’m a noob and havent refactored this yet.
Then i loop though all of the tiles again when i draw and decide which sprite to draw (C++)
if (tilemap[w][h].side == 32 && (tilemap[w][h].corner < 4)) draw->drawSprite(map, w*tileSize, h*tileSize, 5, 2);
This checks if it has a blocked/water tile to the right and a blocked in upper and bottom right corners.
edit
I followed this guide:
http://www.angryfishstudios.com/2011/04/adventures-in-bitmasking/
It is far from the best method though. I’ll be changing to this method in the future:
http://www.gamedev.net/page/resources/_/technical/game-programming/tilemap-based-game-techniques-handling-terrai-r934
Using transparent tiles instead of tiles that contains everything.