RezzaHmt

Binary

Library "Binary"
This library includes functions to convert between decimal and binary numeral formats, and logical and arithmetic operations on binary numbers.

method toBin(value)
  Converts the provided boolean value into binary integers (0 or 1).
  Namespace types: series bool, simple bool, input bool, const bool
  Parameters:
    value (bool): The boolean value to be converted.
  Returns: The converted value in binary integers.

method dec2bin(value, iBits, fBits)
  Converts a decimal number into its binary representation.
  Namespace types: series float, simple float, input float, const float
  Parameters:
    value (float): The decimal number to be converted.
    iBits (int): The number of binary digits allocated for the integer part.
    fBits (int): The number of binary digits allocated for the fractional part.
  Returns: An array containing the binary digits for the integer part at the rightmost positions and the digits for the fractional part at the leftmost positions. The array indexes correspond to the bit positions.

method bin2dec(value, iBits, fBits)
  Converts a binary number into its decimal representation.
  Namespace types: array<int>
  Parameters:
    value (array<int>): The binary number to be converted.
    iBits (int): The number of binary digits allocated for the integer part.
    fBits (int): The number of binary digits allocated for the fractional part.
  Returns: The converted value in decimal format.

method lgcAnd(a, b)
  Bitwise logical AND of two binary numbers. The result of ANDing two binary digits is 1 only if both digits are 1, otherwise, 0.
  Namespace types: array<int>
  Parameters:
    a (array<int>): First binary number.
    b (array<int>): Second binary number.
  Returns: An array containing the logical AND of the inputs.

method lgcOr(a, b)
  Bitwise logical OR of two binary numbers. The result of ORing two binary digits is 0 only if both digits are 0, otherwise, 1.
  Namespace types: array<int>
  Parameters:
    a (array<int>): First binary number.
    b (array<int>): Second binary number.
  Returns: An array containing the logical OR of the inputs.

method lgcXor(a, b)
  Bitwise logical XOR of two binary numbers. The result of XORing two binary digits is 1 only if ONE of the digits is 1, otherwise, 0.
  Namespace types: array<int>
  Parameters:
    a (array<int>): First binary number.
    b (array<int>): Second binary number.
  Returns: An array containing the logical XOR of the inputs.

method lgcNand(a, b)
  Bitwise logical NAND of two binary numbers. The result of NANDing two binary digits is 0 only if both digits are 1, otherwise, 1.
  Namespace types: array<int>
  Parameters:
    a (array<int>): First binary number.
    b (array<int>): Second binary number.
  Returns: An array containing the logical NAND of the inputs.

method lgcNor(a, b)
  Bitwise logical NOR of two binary numbers. The result of NORing two binary digits is 1 only if both digits are 0, otherwise, 0.
  Namespace types: array<int>
  Parameters:
    a (array<int>): First binary number.
    b (array<int>): Second binary number.
  Returns: An array containing the logical NOR of the inputs.

method lgcNot(a)
  Bitwise logical NOT of a binary number. The result of NOTing a binary digit is 0 if the digit is 1, or vice versa.
  Namespace types: array<int>
  Parameters:
    a (array<int>): A binary number.
  Returns: An array containing the logical NOT of the input.

method lgc2sC(a)
  2's complement of a binary number. The 2's complement of a binary number N with n digits is defined as 2^(n) - N.
  Namespace types: array<int>
  Parameters:
    a (array<int>): A binary number.
  Returns: An array containing the 2's complement of the input.

method shift(value, direction, newBit)
  Shifts a binary number in the specified direction by one position.
  Namespace types: array<int>
  Parameters:
    value (array<int>)
    direction (int): The direction of the shift operation.
    newBit (int): The bit to be inserted into the unoccupied slot.
  Returns: A tuple of the shifted binary number and the serial output of the shift operation.

method multiShift(value, direction, newBits)
  Shifts a binary number in the specified direction by multiple positions.
  Namespace types: array<int>
  Parameters:
    value (array<int>)
    direction (int): The direction of the shift operation.
    newBits (array<int>)
  Returns: A tuple of the shifted binary number and the serial output of the shift operation.

method crclrShift(value, direction, count)
  Circularly shifts a binary number in the specified direction by multiple positions. Each ejected bit is inserted from the opposite side.
  Namespace types: array<int>
  Parameters:
    value (array<int>)
    direction (int): The direction of the shift operation.
    count (int): The number of positions to be shifted by.
  Returns: The shifted binary number.

method arithmeticShift(value, direction, count)
  Performs arithmetic shift on a binary number in the specified direction by multiple positions. Every new bit is 0 if the shift is leftward, otherwise, it equals the sign bit.
  Namespace types: array<int>
  Parameters:
    value (array<int>)
    direction (int): The direction of the shift operation.
    count (int): The number of positions to be shifted by.
  Returns: The shifted binary number.

method add(a, b, carry)
  Performs arithmetic addition on two binary numbers.
  Namespace types: array<int>
  Parameters:
    a (array<int>): First binary number.
    b (array<int>): Second binary number.
    carry (int): The input carry of the operation.
  Returns: The result of the arithmetic addition of the inputs.

method sub(a, b, carry)
  Performs arithmetic subtraction on two binary numbers.
  Namespace types: array<int>
  Parameters:
    a (array<int>): First binary number.
    b (array<int>): Second binary number. The number to be subtracted.
    carry (int): The input carry of the operation.
  Returns: The result of the arithmetic subtraction of the input b from the input a.
파인 라이브러리

트레이딩뷰 정신에 따라 오써는 이 파인 코드를 오픈 소스 라이브러리로 퍼블리쉬하여 당사 커뮤니티의 다른 파인 프로그래머들이 쓸 수 있도록 하였습니다. 오써에게 찬사를! 여러분은 이 라이브러리를 프라이빗 또는 오픈 소스 퍼블리케이션에 쓸 수 있지만 퍼블리케이션에 재사용은 하우스룰을 따릅니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

이 라이브러리를 쓰시겠습니까?

텍스트를 클립보드에 카피한 뒤 님의 스크립트에 붙여 넣기.