I need a way to convert integer from decimal form to binary form. I must be possible to specify the bit length of the output bit string. If the length is more than is required for input representation then the extra bits will be padded with 0 or 1 depending on the sign of the input. If the specified bit length is too small for the input number then the procedure must generate an error.
I believe that a solution should exist with the "binary format" procedure in TCL but it has me confused. It seem that the procedure converts into hexadecimal. I am not sure if TCL can do direct conversion the way I need using built-in functions, or I will have to write a custom procedure and do it step by step.