Welcome to the unsigned and signed data types lecture and this lecture I'm going to explain VHDL unsigned
and signed data types what is an unsigned data type and unsigned type is declared in the package numeric
standard and one unsigned data type is there's an array of standard logic which we know a standard logic
is an individual one or a zero a specific bit and a type unsigned is interpreted as a standard logic
vector where we have a group of standard logic.
But the difference is we have different operators available with a of logic vector we have.
We can actually do addition or subtraction Hovell with the unsigned data type we can if we have to unsigned
data types we can take and subtract them or add them to each other.
And also we can manipulate the individual bits which is a major advantage.
We can only with an unsigned type.
We can only represent positive numbers.
We can't represent a negative number.
So once we get down to zero if we subtract one will still say zero we can't go to a negative one.
And in the unsigned data type the leftmost bit is the NSB or the most significant bit.
Let's take a look at an unsigned data type example.
We have the data class which is a signal we have the signal name which is count.
Then we have the colon and the data type which in this case is unsigned and HDL is denoted by just unsigned
and we have the size of the unsigned data type.
So here we have a data with minus one down to zero.
So whenever either data with this if our data is a size of 8 we would take 8 minus one so B 7 down to
zero which would give us a total of 8 bits in our unsigned data type.
And then we have our.
So my coin equals to give us our initial value which we have the other is keyword telling us that all
these bits are set to zero no matter what size.
For example if we want to have a signal a with an unsigned data type we'll make it three down to zero
which gives us 4 bits wide and we want to set that value to 13 which would be the binary value of 1
1 0 1 with your leftmost bit being less inefficient that we Abdus up.
That gives a value of 13.
And if we take another signal we'll call signal B.
I give it an unsigned data type with 3 down to zero which also is an 0 4 bits of one set that night
of 5 and 0 1 0 1 leftmost bit is the most significant bit.
And so that is how you would set the initial value of b to 5 now talk about our signed data types these
are also declared in the package.
Numeric standard just like the unsigned data types are and as well these are an array of stand who logic
just like the unsigned data type.
However the difference between the unsigned versus the signed is that you're signed data types can represent
negative numbers.
And the way they're stored are in twos complement form.
So if you want to represent a negative five depending on the number of bits you specified for your data
type you'll want to take negative five and the two's complement form and store it inside in the leftmost
bit just like the unsigned data type is the MSP or the most significant bit.
Well let's take a look at what a signed data type example looks like.
We have our data class which is a signal.
We have our signal name calling count and data type we're specifying assigned and then the size of that
sign data type.
How many bits is that signed data type.
In this case we're saying data wit minus one down to zero.
So our data with this if we have 8 bits we subtract one gives a 7 down to zero which are give us 8 bit
number for Assigned data type and then the initial value which we are specifying them all to be zeros
which is what the others keyword specifies.
So let's say we have a signal a which is assigned to type signal we'll call it from 3 down to zero.
So that gives us four bits and we want to have a negative three value.
So we have to store this in twos complement.
So that's where we have a 1 1 0 1.
The leftmost bit is used to signify that it's negative.
So we know that's a negative 3 and two's complement form.
Now we want to have a positive five.
We have our signal B which is assigned to type as well.
Three down to zero gives us our four bits and we would specify or initial value is 0 1 0 1 and that's
how you would set assign data type to a value of 5.
And that is the signed unsigned datatypes lecture.