# how to assign hex value to a variable

Status
Not open for further replies.

#### j hemangini

##### Member level 1 assign hex value

I want to creat a code in which there is variabe name let Data_Byte and want assign hex value 0x41, initially to this variable. Binary equivalent of this value is
01000001. According to my requirement after every 100 clock cycle only one bit should be on out pin (from bit no 0 to 7 one by one after every 100 clock cycle).

So the main thing i want to ask is that how can i define this variable and how one bit can be transferred from this value.

thank you.

#### llopacinski2

##### Newbie level 2 assign hex values in vhdl

If I understood:

vhdl:

signal Data_Byte : std_logic_vector( 7 downto 0) := x"41";

fifth bit:
one_bit <= Data_Byte(5); --(data conversion can be needed)

verilog:

reg [7:0] Data_Byte = 8'h41;

fifth_bit = Data_Byte[ 5];

### j hemangini

Points: 2

#### saikat

##### Member level 2 vhdl assign hex

You have to use "signal" not "variable" in order to put it on FPGA pin.

first declare it..
signal Data_Byte : std_logic_vector(7 downto 0);

hex value assignment..
Data_Byte <= x"BC";

Data_Byte <= x"01";

then every 100th clock edge, left rotate (by one bit) the whole register content.

#### j hemangini

##### Member level 1 vhdl assign value

now i understood how to define hex value.
But what instruction should i write for shift right.
Thank you.

#### saikat

##### Member level 2 assigning hex values to #define

Shift operators:

Let A = “10010101”

A sll 2 = “01010100” --shift left logical, filled with ‘0’
A srl 3 = “00010010” --shift right logical, filled with ‘0’
A sla 3 = “10101111” --shift left arithmetic, filled with right bit
A sra 2 = “11100101” --shift right arithmetic, filled with left bit
A rol 3 = “10101100” --rotate left by 3
A ror 5 = “10101100” --rotate right by 5

where sll, srl, sla, sra, rol, ror are vhdl keywords.

For your application, you have to use: "A rol 1"

### j hemangini

Points: 2

#### j hemangini

##### Member level 1 I m very greatful to u.
thank you.

Status
Not open for further replies.