Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 16-bit unsigned integer log base 2:
- * out = log2(a)
- */
- CHIP Log16 {
- IN a[16];
- OUT out[16];
- PARTS:
- // Put your code here:
- //0000
- //1000
- //0100
- //1100
- //0010
- //1010
- //0110
- //1110
- Mux16(a=false, b[0]=true, b[1]=false, b[2]=false, b[3]=false, b[4..15]=false, sel=a[1], out=out1);
- Mux16(a=out1, b[0]=false, b[1]=true, b[2]=false, b[3]=false, b[4..15]=false, sel=a[2], out=out2);
- Mux16(a=out2, b[0]=true, b[1]=true, b[2]=false, b[3]=false, b[4..15]=false, sel=a[3], out=out3);
- Mux16(a=out3, b[0]=false, b[1]=false, b[2]=true, b[3]=false, b[4..15]=false, sel=a[4], out=out4);
- Mux16(a=out4, b[0]=true, b[1]=false, b[2]=true, b[3]=false, b[4..15]=false, sel=a[5], out=out5);
- Mux16(a=out5, b[0]=false, b[1]=true, b[2]=true, b[3]=false, b[4..15]=false, sel=a[6], out=out6);
- Mux16(a=out6, b[0]=true, b[1]=true, b[2]=true, b[3]=false, b[4..15]=false, sel=a[7], out=out7);
- Mux16(a=out7, b[0]=false, b[1]=false, b[2]=false, b[3]=true, b[4..15]=false, sel=a[8], out=out8);
- Mux16(a=out8, b[0]=true, b[1]=false, b[2]=false, b[3]=true, b[4..15]=false, sel=a[9], out=out9);
- Mux16(a=out9, b[0]=false, b[1]=true, b[2]=false, b[3]=true, b[4..15]=false, sel=a[10], out=out10);
- Mux16(a=out10, b[0]=true, b[1]=true, b[2]=false, b[3]=true, b[4..15]=false, sel=a[11], out=out11);
- Mux16(a=out11, b[0]=false, b[1]=false, b[2]=true, b[3]=true, b[4..15]=false, sel=a[12], out=out12);
- Mux16(a=out12, b[0]=true, b[1]=false, b[2]=true, b[3]=true, b[4..15]=false, sel=a[13], out=out13);
- Mux16(a=out13, b[0]=false, b[1]=true, b[2]=true, b[3]=true, b[4..15]=false, sel=a[14], out=out14);
- Mux16(a=out14, b[0]=true, b[1]=true, b[2]=true, b[3]=true, b[4..15]=false, sel=a[15], out=out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement