Differences between revisions 1 and 2
Revision 1 as of 2023-01-21 06:04:44
Size: 2582
Comment:
Revision 2 as of 2023-01-21 06:08:57
Size: 3195
Comment:
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:

----



== Numeric Literals ==

Literals follow the C language definition.

A leading `0` indicates an octal number.

A leading `0x` or `0X` indicates hexadecimal.

Otherwise, numbers take the form `[base#]n`, where `base` is a decimal number between 2 and 64 representing the arithmetic base. If `base#` is omitted, the default of base 10 applies. When specifying `n`, if a non-digit is required, the digits greater than 9 are represented by lowercase letters, uppercase letters, `@`, and `_`, in that order. If `base` is less than or equal to 36, lowercase and uppercase letters are interchange.

Bash Arithmetic


Numeric Literals

Literals follow the C language definition.

A leading 0 indicates an octal number.

A leading 0x or 0X indicates hexadecimal.

Otherwise, numbers take the form [base#]n, where base is a decimal number between 2 and 64 representing the arithmetic base. If base# is omitted, the default of base 10 applies. When specifying n, if a non-digit is required, the digits greater than 9 are represented by lowercase letters, uppercase letters, @, and _, in that order. If base is less than or equal to 36, lowercase and uppercase letters are interchange.


Unary Operators

Unary operators have the highest priority.

Operator

Meaning

a++

post-increment $a

a--

post-decrement $a

++a

pre-increment $a

--a

pre-decrement $a

+

positive

-

negative

!

negation


Binary Operators

The binary operators include arithmetic and logic operations.

Operator

Meaning

*

multiplication

/

division

%

remainder

+

addition

-

subtraction

**

exponentiation

<

less than

>

greater than

<=

less than or equal

>=

greater than or equal

==

equality

!=

inequality


Ternary Operators

There is just one ternary operator:

a ? b : c

a is the test, b is the value if true, and c is the value if false.

Note that ternary operators follow logic operators as well.


Assignment

Operator

Meaning

a = b

assignment

a *= b

a = a * b

a /= b

a = a / b

a %= b

a = a % b

a += b

a = a + b

a -= b

a = a - b

Note that ternary operators follow logic operators as well.


Bit-wise Operators

Operator

Meaning

~

negation

<<

bitshift left

>>

bitshift right

&

AND

^

XOR

|

OR

a <<= b

a = a << b

a >>= b

a = a >> b

a &= b

a = a & b

a ^= b

a = a ^ b

a |= b

a = a | b

Note that negation has equal precedence to other unary operators; bitshifts (such as <<) follow arithmetic operators; bit-wise logic (such as &) come after all other binary operators; and bit-wise assignment operators (such as <<=) have equal precedence to other assignment operators.


CategoryRicottone

Bash/Arithmetic (last edited 2023-01-29 21:14:38 by DominicRicottone)