본문 바로가기
CAN/CAPL

CAPL 연산자 정리

by 임아톰 2023. 3. 30.

CAPL Operator는 대부분 C 언어의 Operator와 유사합니다.

CAPL에는 다음과 같은 Operator를 지원합니다.

Operator Description Example
+        - Addition, subtraction  
*        / Multiplication, division  
++     -- Increment or decrement by 1 a++;        // increments a by 1
% Modulo division (returns integer remainder of a division) a = 4 % 3; // a is 1
<        <= Less than; less than or equal to returns TRUE or FALSE
>        >= Greater than; greater than or equal to returns TRUE or FALSE
==      != Compare for equality or inequality returns TRUE or FALSE
&& Logic AND returns TRUE or FALSE
|| Logic OR returns TRUE or FALSE
! Logic NOT changes TRUE to FALSE and vice versa
& Bitwise AND 1 & 7 // yields 1 (0001 & 0111 -> 0001)
| Bitwise OR 1 | 7 // yields 7 (0001 | 0111 -> 0111)
~ Bitwise complement ~1 // yields 14 (0001  1110)
^ Bitwise exclusive OR (XOR) 01^11 // ergibt 10
>>      << Bit shift to right or left 1 << 3 // yields 8 (0001  1000)

특이한건 ! 연산자를 지원해서 bit 반전 등에 사용할 수 있습니다.

반응형

'CAN > CAPL' 카테고리의 다른 글

CAPL 시그널 읽고 쓰는 방법  (0) 2023.04.01
CAPL 이벤트 종류  (0) 2023.03.29