Sar Function

Purpose

Shifts a bit pattern to the right.

Syntax

% = Sar(m, n)32 bit operation

% = Sar%(m, n)32 bit operation

Large = Sar8(m, n)64 bit operation

&=Sar&(m, n)16 bit operation

Word = Sarw(m, n) 16 bit operation

| = Sar|(m, n)8 bit operation

Description

Sar(m, n) shifts a bit pattern of an integer expression m n steps to the right (Sar = Shift Right), in which the highest bit is copied (and not replaced with zero like with Shr). Each bit shift right is a division by two. An example:

x = -8 : Sar x, 3 or -8 Sar 3 or Sar(-8, 3)

-8 as binary: 1111 1111 1111 1111 1111 1111 1111 0111

Shift: 1111 1111 1111 1111 1111 1111 1111 1011

Shift: 1011 1111 1111 1111 1111 1111 1111 1101

Shift: 1001 1111 1111 1111 1111 1111 1111 1110

Example

Debug.Show

Trace Sar(-8, 1) // = -4

Trace Sar(-8, 2) // = -2

Trace Sar(-8, 3) // = -1

Trace -8 Sar 3   // = -1

Remarks

Sar can also be used as an operator:

m Sar n32-bits operation

m Sar8 n64 bits operation

See Also

Shr, Shl, Ror, Rol

{Created by Sjouke Hamstra; Last updated: 22/10/2014 by James Gaite}