"The variable len indicates the buffer length in bytes."
"The variable len indicates the buffer length by the byte."
I'm a computer programmer, so I know 1 is far more common than 2.
However, please consider the following two sentences:
"He is paid by the hour"
"He is paid in hours"
I also know 3 is far more common than 4.
Which of these phrases should be used in what scenarios?