FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > VHDL

VHDL comp.lang.vhdl newsgroup / Usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-27-2007, 12:48 AM
Dan
Guest
 
Posts: n/a
Default MSB in std_logic_vector

Hi,

I would like to get the most significant bit from a std_logic_vector, so
that I can deduce if it's a signed or unsigned binary number. How can I do
this?

Reply With Quote
  #2 (permalink)  
Old 11-27-2007, 01:03 AM
Eric Smith
Guest
 
Posts: n/a
Default Re: MSB in std_logic_vector

Dan wrote:
> I would like to get the most significant bit from a std_logic_vector,
> so that I can deduce if it's a signed or unsigned binary number. How
> can I do this?


If you know how the signal/type is declared, just index the appropriate
bit. For isntance, if it is:

signal foo: std_logic_vector (11 downto 0);

you could use foo (11).

In a situation where the declaration may not be visible, you can
use the 'left attribute, e.g., foo (foo'left). That might be a good
idea even when you know the index, as it makes it more clear that
you're selecting the leftmost bit, and it won't break if the width
of the signal changes.

You can also use IEEE.numeric_std, and cast the std_logic_vector
into the type "signed", and then use a numeric comparison against
0 (or other numeric literals).

Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 01:35 AM
KJ
Guest
 
Posts: n/a
Default Re: MSB in std_logic_vector


"Dan" <[email protected]> wrote in message
news:fifm0r$nvq$[email protected]..
> Hi,
>
> I would like to get the most significant bit from a std_logic_vector, so
> that I can deduce if it's a signed or unsigned binary number. How can I do
> this?


If the vector is representing a signed number then you'll be much farther
ahead if you use the ieee.numeric_std package to work with instead.

But the straightforward way to get the MSB of a vector 'vec' without having
to hardcode a particular bit number (which is subject to change) is the
following

vec_msb <= vec(vec'left);

KJ


Reply With Quote
  #4 (permalink)  
Old 11-27-2007, 02:11 AM
Mike Treseler
Guest
 
Posts: n/a
Default Re: MSB in std_logic_vector

Dan wrote:

> I would like to get the most significant bit from a std_logic_vector, so
> that I can deduce if it's a signed or unsigned binary number. How can I
> do this?


A std_logic_vector is just an array of bits.
If I happen to know that the value is signed, the
msb is usually the sign bit, but I certainly can't
determine the type by the value of the msb.

-- Mike Treseler
Reply With Quote
  #5 (permalink)  
Old 11-27-2007, 04:34 PM
Andy
Guest
 
Posts: n/a
Default Re: MSB in std_logic_vector

On Nov 26, 7:11 pm, Mike Treseler <mike_trese...@comcast.net> wrote:
> Dan wrote:
> > I would like to get the most significant bit from a std_logic_vector, so
> > that I can deduce if it's a signed or unsigned binary number. How can I
> > do this?

>
> A std_logic_vector is just an array of bits.
> If I happen to know that the value is signed, the
> msb is usually the sign bit, but I certainly can't
> determine the type by the value of the msb.
>
> -- Mike Treseler


Dan,

What Mike is trying to say, is that your original question states you
want to determine whether a value is signed or unsigned. Those are
representations (types), not values. If you meant "negative or
positive", and you know the representation is signed (obviously,
otherwise there would be no negative values to consider), then, yes
the MSB will tell you that. Otherwise, the MSB value tells you nothing
about representation.

This is the reasoning behind the numeric_std package and its
definitions of types signed and unsigned: because it is impossible for
VHDL to know the numeric representation of an SLV. Defining the data
as signed or unsigned (by putting it in the appropriate type of signal
or variable) allows VHDL to automatically select the appropriate
operator version to ensure that the results are arithmetically
correct.

Andy
Reply With Quote
  #6 (permalink)  
Old 11-30-2007, 01:32 AM
Dan
Guest
 
Posts: n/a
Default Re: MSB in std_logic_vector

Thanks all

Dan,


"Andy" <[email protected]> wrote in message
news:[email protected]...
> On Nov 26, 7:11 pm, Mike Treseler <mike_trese...@comcast.net> wrote:
>> Dan wrote:
>> > I would like to get the most significant bit from a std_logic_vector,
>> > so
>> > that I can deduce if it's a signed or unsigned binary number. How can I
>> > do this?

>>
>> A std_logic_vector is just an array of bits.
>> If I happen to know that the value is signed, the
>> msb is usually the sign bit, but I certainly can't
>> determine the type by the value of the msb.
>>
>> -- Mike Treseler

>
> Dan,
>
> What Mike is trying to say, is that your original question states you
> want to determine whether a value is signed or unsigned. Those are
> representations (types), not values. If you meant "negative or
> positive", and you know the representation is signed (obviously,
> otherwise there would be no negative values to consider), then, yes
> the MSB will tell you that. Otherwise, the MSB value tells you nothing
> about representation.
>
> This is the reasoning behind the numeric_std package and its
> definitions of types signed and unsigned: because it is impossible for
> VHDL to know the numeric representation of an SLV. Defining the data
> as signed or unsigned (by putting it in the appropriate type of signal
> or variable) allows VHDL to automatically select the appropriate
> operator version to ensure that the results are arithmetically
> correct.
>
> Andy


Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
inout std_logic_vector to array of std_logic_vector of generic length conversion... Thomas Rouam VHDL 6 11-09-2007 12:49 PM
std_logic_vector ==> interger? uvbaz VHDL 6 09-12-2006 10:13 AM
std_logic_vector on a single pin [email protected] VHDL 1 07-09-2006 01:16 PM
HEX to STD_LOGIC_VECTOR [email protected] VHDL 2 06-06-2005 04:11 AM
Integer or STD_LOGIC_VECTOR jk VHDL 3 01-14-2004 11:29 PM


All times are GMT +1. The time now is 03:03 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved