The fact that we're discussing this at all is a reasonable argument for using a library function.
Not that it matters. I don't even think that there's a single piece of software in the world which would actually care about these bits rather than treating the whole byte array as opaque thing.