Your description is still unclear. I think you mean "find a given 1k string within another string of 2k, a position which may not by byte-aligned". But there is nothing especially subtle about the bit-alignment aspect (though I think you misuse "memory" in hopes of expressing this).
One very simple solution is just to perform 8 searches for bit-shifted versions of pattern1 within pattern2 (with suitable handling of the edges). Another would be to define a hash function defined on sequence of 8k bits - performing the bitwise match on pattern2 will cost at most 8k hash evaluations (plus one hash on pattern1). With either approach, you don't necessarily have to search for the whole pattern1 (either by byte comparisons or by hash): just find matches for a shorter substring, and only consider those partial matches when verifying a full match.
Of course, it's also true that the entire literature on string matching applies to this case perfectly well - which makes me wonder why the question is being asked...
yes, of course: content can be extracted from docx files and compared to plain text. if by "machine language" you mean "executable code", it's even easier, since executable formats are very well-documented.
the real issue here is what you mean by "compare". if you're extracting text, do you mean specifically to ignore formatting? for executables, do you only want to compare executable instructions, ignoring all the data and metadata (symbol names, etc)?
On linux, pdftotxt uses ghostscript to render a PDF to plain text; I'm certain LibreOffice could be used to extract text from a docx file. To exposed machine code from an executable, the obvious solution would be objdump or realelf.