Multi-Bit Versions of Basic Gates??

Thread Starter

jeyjey

Joined Dec 12, 2010
1
Hello everyone,

I am new to this forum and I have a question regarding multi-bit logic gates.

I am trying to understand how does a multi-bit gate works, here is a 16-bit AND gate as an example:

/**
* 16-bit and gate. For i=0..15 out = a and b
*/

CHIP And16 {

IN a[16], b[16];
OUT out[16];

BUILTIN And;
}

This code is written in HDL(Hardware descriptive language) and when I run it in a hardware simulator, for these inputs:
a[16]=10000
b[16]=11111
I get: out[16]=8960

Can someone make me understand how did it compute this number?
I thought that it would compare each bit alone and output either 0 or 1
for example:
a[16]= 10000
b[16]= 11111
out[16]= 10000

Thanks!
 

Wendy

Joined Mar 24, 2008
23,429
When you say 16 bit AND gate I think of a simple AND gate with 16 inputs. There is a nomenclature associated with this style of electronics. You are mixing up basic digital electronics and programming, which creates confusion. It appears you are talking about a software gate.

When talking gates binary is the math of choice, though other bases for number systems can be used. Ultimately binary is what the gate uses, so the off base numbers will have to be translated into binary at some point to understand how the gate will process them.
 
For future people who may run into this via Google as I did...

The issue you were having is that the a[16]= 10000 you set is not binary, it is decimal. I'm not certain the convention for writing binary as you intended in the code, but if you convert those values to binary and then compare them as you expected... you get:

10011100010000 = 10000 (base 10)
10101101100111 = 11111 (base 10)
10001100000000 = 8960 (base 10)

comparing the 10000 to the 11111 as you can see is done bit by bit, but the resultant binary number is not equal to 10000 (base 10).
 
Top