[Include] rBits [supports 16, 8, 4, 2 and 1-bit arrays]
#48

Just renamed most functions/defines so they don't conflict with YSI.

to anyone that wants it:
Code:
/*
	SA-MP "rBits" Include
	Copyright © 2011 RyDeR`
*/

#if defined _Included_rBits
	#endinput
#endif

#define _Included_rBits

#define BIT_TAGS \
	{ rBit1, rBit2, rBit4, rBit8, rBit16 }

enum e_Bits
{
	rBit1,
	rBit2,
	rBit4,
	rBit8,
	rBit16,
	rBit32
};

#define rBit1:%0<%1> \
	rBit1: %0[((%1) + 31) >>> _: rBit32]

#define	rBit1_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit1)

#define rBit1_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit1)

#define rBit2:%0<%1> \
	rBit2: %0[((%1) + 15) >>> _: (rBit32 - rBit2)]

#define	rBit2_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit2)

#define rBit2_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit2)

#define rBit4:%0<%1> \
	rBit4: %0[((%1) + 7) >>> _: (rBit32 - rBit4)]

#define	rBit4_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit4)

#define rBit4_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit4)

#define rBit8:%0<%1> \
	rBit8: %0[(%1) char]

#define rBit8_Set(%0,%1,%2) \
	(_: %0{(%1)} = (%2))

#define rBit8_Get(%0,%1) \
	(_: %0{(%1)})

#define rBit16:%0<%1> \
	rBit16: %0[((%1) + 1) >>> _: (rBit32 - rBit16)]

#define	rBit16_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit16)

#define rBit16_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit16)

stock rBit_Set(BIT_TAGS: bitArr[], arrIdx, value, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
	new
		bitVar = ((arrIdx & ((1 << _: (rBit32 - bitShift)) - 1)) << _: bitShift),
		bitLim = ((1 << (1 << _: bitShift)) - 1)
	;
	if(!(0 <= (arrIdx >>>= _: (rBit32 - bitShift)) < arrSize))
		return 0;

	(_: bitArr[arrIdx]) &= ~(bitLim << bitVar);
	(_: bitArr[arrIdx]) |= ((bitLim & value) << bitVar);

	return 1;
}

stock rBit_Get(BIT_TAGS: bitArr[], arrIdx, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
	new
		bitVar = ((arrIdx & ((1 << _: (rBit32 - bitShift)) - 1)) << _: bitShift),
		bitLim = ((1 << (1 << _: bitShift)) - 1)
	;
	if(!(0 <= (arrIdx >>>= _: (rBit32 - bitShift)) < arrSize))
		return 0;

	return ((_: bitArr[arrIdx] >>> bitVar) & bitLim);
}
You just need to add a 'r' next to your function(s).
Reply


Messages In This Thread
rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 08.08.2011, 14:47
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Ash. - 08.08.2011, 14:50
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by VivianKris - 08.08.2011, 14:54
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 14:56
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 08.08.2011, 15:07
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 15:09
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Kaperstone - 08.08.2011, 15:23
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by OUL - 08.08.2011, 15:27
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 08.08.2011, 15:31
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by OUL - 08.08.2011, 15:35
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 15:38
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Double-O-Seven - 08.08.2011, 15:54
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 16:06
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by vyper - 08.08.2011, 16:08
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by OUL - 08.08.2011, 16:14
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Double-O-Seven - 08.08.2011, 16:21
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by OUL - 08.08.2011, 16:22
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 08.08.2011, 16:23
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by OUL - 08.08.2011, 16:26
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 16:26
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 08.08.2011, 16:38
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 16:43
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by OUL - 08.08.2011, 16:47
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 16:56
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by OUL - 08.08.2011, 16:58
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Zh3r0 - 08.08.2011, 16:59
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Toni - 08.08.2011, 17:12
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Kaperstone - 08.08.2011, 21:21
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Double-O-Seven - 14.08.2011, 08:33
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 14.08.2011, 13:08
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Lorenc_ - 18.08.2011, 11:06
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by royal_king - 18.08.2011, 11:23
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by System64 - 18.08.2011, 11:49
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 18.08.2011, 11:58
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Rock_Ro - 18.08.2011, 15:03
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by System64 - 18.08.2011, 16:47
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 19.08.2011, 09:22
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by System64 - 19.08.2011, 10:27
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 19.08.2011, 15:23
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Riddick94 - 19.08.2011, 15:50
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Lorenc_ - 21.08.2011, 01:43
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 21.08.2011, 02:17
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by System64 - 21.08.2011, 14:11
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by GangsTa_ - 22.08.2011, 15:52
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Lorenc_ - 24.08.2011, 09:03
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Gh0sT_ - 28.08.2011, 00:14
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 28.08.2011, 02:37
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Lorenc_ - 28.08.2011, 03:46
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by System64 - 28.08.2011, 08:45
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by oFLu - 28.08.2011, 08:50
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Dwane - 08.02.2012, 18:15
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 08.02.2012, 18:21
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Dwane - 08.02.2012, 19:27
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by RyDeR` - 23.02.2012, 23:10
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Dwane - 27.02.2012, 20:54
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Slice - 05.02.2016, 12:11
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by IgoRangel - 02.08.2016, 23:43
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by justice96 - 10.08.2016, 00:42
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by AbyssMorgan - 10.08.2016, 07:09
Re: rBits [supports 16, 8, 4, 2 and 1-bit arrays] - by Bussyman - 27.04.2017, 08:54

Forum Jump:


Users browsing this thread: 11 Guest(s)