Search code examples
binaryhexbit-manipulationvhdlhardware

Representing 2 binary digits in hex for vhdl


In VHDL, If X'1 => "0001", X'3 => "0011". i.e, 1 hex digit represents 4 binary values, how do i represent only 2 binary values in hex given that i have only a specific bit range in memory. In this case 2. For instance, the space left in memory can only take 2 bits. I know i can still use the initial representation and mask out either the two msb's or lsb's but is there another way ?


Solution

  • You can do this if you are using VHDL-2008:

    2X"2" = "0010"
    

    Further examples from web:

    unsigned notation (default):

    7UX"F"  = "0001111" -- extend
    7UX"0F" = "0001111" -- reduce
    

    signed notation:

    7SX"F"  = "1111111" -- extend
    7SX"CF" = "1001111" -- reduce