SHARE
TWEET

Untitled

a guest Jul 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * 16-bit unsigned integer log base 2:
  3.  * out = log2(a)
  4.  */
  5.  
  6. CHIP Log16 {
  7.     IN a[16];
  8.     OUT out[16];
  9.  
  10.     PARTS:
  11.     // Put your code here:
  12.         //0000
  13.         //1000
  14.         //0100
  15.         //1100
  16.         //0010
  17.         //1010
  18.         //0110
  19.         //1110
  20.  
  21.         Mux16(a=false, b[0]=true, b[1]=false, b[2]=false, b[3]=false, b[4..15]=false, sel=a[1], out=out1);
  22.         Mux16(a=out1,  b[0]=false, b[1]=true, b[2]=false, b[3]=false, b[4..15]=false, sel=a[2], out=out2);
  23.         Mux16(a=out2,  b[0]=true, b[1]=true, b[2]=false, b[3]=false, b[4..15]=false, sel=a[3], out=out3);
  24.         Mux16(a=out3,  b[0]=false, b[1]=false, b[2]=true, b[3]=false, b[4..15]=false, sel=a[4], out=out4);
  25.         Mux16(a=out4,  b[0]=true, b[1]=false, b[2]=true, b[3]=false, b[4..15]=false, sel=a[5], out=out5);
  26.         Mux16(a=out5,  b[0]=false, b[1]=true, b[2]=true, b[3]=false, b[4..15]=false, sel=a[6], out=out6);
  27.         Mux16(a=out6,  b[0]=true, b[1]=true, b[2]=true, b[3]=false, b[4..15]=false, sel=a[7], out=out7);
  28.         Mux16(a=out7,  b[0]=false, b[1]=false, b[2]=false, b[3]=true, b[4..15]=false, sel=a[8], out=out8);
  29.         Mux16(a=out8,  b[0]=true, b[1]=false, b[2]=false, b[3]=true, b[4..15]=false, sel=a[9], out=out9);
  30.         Mux16(a=out9,  b[0]=false, b[1]=true, b[2]=false, b[3]=true, b[4..15]=false, sel=a[10], out=out10);
  31.         Mux16(a=out10,  b[0]=true, b[1]=true, b[2]=false, b[3]=true, b[4..15]=false, sel=a[11], out=out11);
  32.         Mux16(a=out11,  b[0]=false, b[1]=false, b[2]=true, b[3]=true, b[4..15]=false, sel=a[12], out=out12);
  33.         Mux16(a=out12,  b[0]=true, b[1]=false, b[2]=true, b[3]=true, b[4..15]=false, sel=a[13], out=out13);
  34.         Mux16(a=out13,  b[0]=false, b[1]=true, b[2]=true, b[3]=true, b[4..15]=false, sel=a[14], out=out14);
  35.         Mux16(a=out14,  b[0]=true, b[1]=true, b[2]=true, b[3]=true, b[4..15]=false, sel=a[15], out=out);
  36.    
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top