I have a situation where I need to store a large number of long case-insensitive alphabetic strings in RAM. I need to conserve as much space as possible.

My thinking is that since I only have 27 values (26 letters plus null) to represent for each character, I can get away with having each character represented by only 5 bits instead of the usual 7 (actually 8) bit ASCII.

Its easy enough to reduce an 8 bit ASCII char to 5 bits by doing a bitwise AND of each 8 bit char with 0001 1111 and then left shift by 3 to get the character I need primed into 5 bit representation.

However, I have no idea how I would go about writing this to RAM, and then have the next character come right after starting at the next unused bit and so on. The problem is that I will have single characters spanning byte-byte gaps.

essentially i want RAM to look like this:
e.g. i have eight characters named a,b,c,d,e,f,g,h

aaaaabbb bbcccccd ddddeeee efffffgg ggghhhhh

(the above shows five bytes according to which character each bit is part of)

except that I wont always be writing in nice blocks of 8 characters so that we get a nice even 5 bytes.

I'm not sure if it is possible to do this, perhaps I might be able to inline assembly code if it can't be done in C proper?

Also, I don't really care how the characters are stored, data type doesn't matter. all i want to do is be able to read and write these raw numeric values easily.

Thanks. (I'm new to programming, so if this is a completely crazy question I apologize :-) )