#This work is licensed under the
#Creative Commons Attribution-Share Alike 3.0 United States License.
#To view a copy of this license, visit
#http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
#Creative Commons,
#171 Second Street, Suite 300,
#San Francisco, California, 94105, USA.

INPUT bit_count,unsigned_;
OUTPUT "an unsigned value written to the stream";
VAR unsigned_ "unsigned value";
VAR bit_count "bit count";
VAR MSB "MSB";
VAR LSB "LSB";
VAR written "written value";
MSB <- floor(unsigned_ / 2 ^ bit_count);
LSB <- unsigned_ - MSB * 2 ^ bit_count;
MSB -> write unary 1;
LSB -> write bit_count unsigned;
return written;
