<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/BitArShift?action=history&amp;feed=atom</id>
	<title>BitArShift - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/BitArShift?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BitArShift&amp;action=history"/>
	<updated>2026-05-09T17:35:33Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=BitArShift&amp;diff=46743&amp;oldid=prev</id>
		<title>Necktrox: Grammar</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BitArShift&amp;diff=46743&amp;oldid=prev"/>
		<updated>2016-02-22T01:10:24Z</updated>

		<summary type="html">&lt;p&gt;Grammar&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:10, 22 February 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot;&gt;Line 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Shared function}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Shared function}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This functions performs an arithmetic shift on the integer '''value''' by integer '''n''' positions. In &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/del&gt;''arithmetic shift'', zeros are shifted in to replace the discarded bits. In a ''right arithmetic'' shift, the [https://en.wikipedia.org/wiki/Sign_bit sign bit] is shifted in on the left, thus preserving the sign of the operand.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This functions performs an arithmetic shift on the integer '''value''' by integer '''n''' positions. In &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;an &lt;/ins&gt;''arithmetic shift'', zeros are shifted in to replace the discarded bits. In a ''right arithmetic'' shift, the [https://en.wikipedia.org/wiki/Sign_bit sign bit] is shifted in on the left, thus preserving the sign of the operand.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift Bitwise operation] for more details.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift Bitwise operation] for more details.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-46741:rev-46743 --&gt;
&lt;/table&gt;</summary>
		<author><name>Necktrox</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=BitArShift&amp;diff=46741&amp;oldid=prev</id>
		<title>Necktrox: Added page for bitArShift</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BitArShift&amp;diff=46741&amp;oldid=prev"/>
		<updated>2016-02-21T22:40:48Z</updated>

		<summary type="html">&lt;p&gt;Added page for bitArShift&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
&lt;br /&gt;
This functions performs an arithmetic shift on the integer '''value''' by integer '''n''' positions. In a ''arithmetic shift'', zeros are shifted in to replace the discarded bits. In a ''right arithmetic'' shift, the [https://en.wikipedia.org/wiki/Sign_bit sign bit] is shifted in on the left, thus preserving the sign of the operand.&lt;br /&gt;
See [https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift Bitwise operation] for more details.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
int bitArShift ( int value, int n )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required arguments===&lt;br /&gt;
*'''value:''' The value you want to perform the arithmetic shift on.&lt;br /&gt;
*'''n:''' The amount of positions to shift the value by.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the arithmetic shifted value as ''integer''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example adds the clientside command '''/arshift [value] [positions = 1]''', which will print the result from the function [[bitArShift]].&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function getNumberAsBitString(value)&lt;br /&gt;
    if type(value) ~= 'number' then&lt;br /&gt;
        return false&lt;br /&gt;
    else&lt;br /&gt;
        local binary = ''&lt;br /&gt;
&lt;br /&gt;
        for field = 31, 0, -1 do&lt;br /&gt;
            binary = binary .. bitExtract(value, field)&lt;br /&gt;
&lt;br /&gt;
            if field % 4 == 0 then&lt;br /&gt;
                binary = binary ..' '&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        return binary&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addCommandHandler('arshift',&lt;br /&gt;
    function (command, value, positions)&lt;br /&gt;
        if type(value) ~= 'string' or value:len() == 0 then&lt;br /&gt;
            return outputChatBox('* Syntax: /arshift [value] [positions = 1]')&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if type(positions) ~= 'string' or positions:len() == 0 then&lt;br /&gt;
            positions = 1&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        local result = bitArShift(tonumber(value), tonumber(positions))&lt;br /&gt;
        local binary = getNumberAsBitString(result)&lt;br /&gt;
&lt;br /&gt;
        outputChatBox('* Decimal: '.. result ..', Binary: '.. binary)&lt;br /&gt;
    end&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If you trigger the command with '''/arshift 0xF0 4''' and '''/arshift 0xF0 -4''' you will receive as response:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
* Decimal: 15,   Binary: 0000 0000 0000 0000 0000 0000 0000 1111&lt;br /&gt;
* Decimal: 3840, Binary: 0000 0000 0000 0000 0000 1111 0000 0000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Bit_functions}}&lt;/div&gt;</summary>
		<author><name>Necktrox</name></author>
	</entry>
</feed>