본문 바로가기
HW Design/1. Verilog HDL Basic

[Verilog Operator] 5. 시프트 연산자

by 한PU 2024. 1. 4.
728x90
반응형
  • == 시프트 연산자
  • 특정한 논리 함수를 위해 사용

Table

연산자 표현
<< shift left logical
>> shift right logical
<<< shift left arithmetic
>>> shift right arithmetic
  • 디지털 회로를 design 할 때, shift 연산을 자주 사용
  • 두 개의 인수(argument) 필요
      1. 시프트 하려는 신호의 이름
      1. 이동하려는 비트
  • logical shift operators 를 사용하면, 신호가 필요한 비트 수 만큼 shift 된 후 모든 빈 위치에 0b가 채워짐.
  • arithmetic shift operators 는 shift된 신호의 부호를 유지
// a 신호를 왼쪽으로 3 bits 이동
a = a << 3;

// b 신호를 오른쪽으로 8 bits 이동
b = b >> 8;

// arithemtic operator를 이용하여, c 신호를 왼쪽으로 2 bits 이동
// 이런 상황에서는, c 신호를 signed type으로 만들기 위해 casting
c = $signed(c) <<< 3;

// arithemtic operator를 이용하여, d 신호를 오른쪽으로 5 bits 이동
// d 가 이미 signed type 신호일 때
d = d >>> 5;
728x90
반응형