[Include] DBits - 16-bit and 8-bit arrays support.
#17

Thanks for the comments.



Quote:
Originally Posted by Y_Less
Посмотреть сообщение
I would also point out this:

pawn Код:
#define Bit16_Get(%0,%1) (%0[(%1)>>>1]&(0x0000FFFF<<(((%1)&1)<<4)))
Directly based on the code in y_bits, which leads instantly on to:

pawn Код:
#define Bit4_Get(%0,%1) (%0[(%1)>>>3]&(0x0000000F<<(((%1)&7)<<2)))
As the basis of a nibble system.

In general (where "%2" is the size of data, only works with powers of 2). Note that this assumes a 32-bit cell size (the full generic solution is harder).

pawn Код:
#define BitX_Mask(%2)   ((1 << (%2)) - 1)
#define BitX_Log(%2)    log2(%2)
#define BitX_Shift(%2)  (5 - BitX_Log(%2))
#define BitX_Filter(%2) ((1 << BitX_Shift(%2)) - 1)

#define BitX_Get(%0,%1,%2) (%0[(%1) >>> BitX_Shift(%2)] & (BitX_Mask(%2) << (((%1) & BitX_Filter(%2)) << BitX_Log(%2))))
I've added extra brackets for convenience, and you're best off pre-calculating bits. For reference, here is log2 (base 2 logarithm) for relevant values:

pawn Код:
1 = 0
2 = 1
4 = 2
8 = 3
16 = 4
32 = 5
To be honest I don't understand, and I think I won't for some time... xD
Reply


Messages In This Thread
DBits - 16-bit and 8-bit arrays support. - by MrDeath537 - 14.06.2011, 11:26
Re: DBits - 16-bit and 8-bit arrays support. - by SpiderWalk - 14.06.2011, 11:41
Re: DBits - 16-bit and 8-bit arrays support. - by Edvin - 14.06.2011, 11:44
Re: DBits - 16-bit and 8-bit arrays support. - by Mr.GeEk - 14.06.2011, 12:07
Re: DBits - 16-bit and 8-bit arrays support. - by tarmo - 14.06.2011, 12:25
Re: DBits - 16-bit and 8-bit arrays support. - by Anzipane! - 14.06.2011, 13:07
Re: DBits - 16-bit and 8-bit arrays support. - by Double-O-Seven - 14.06.2011, 13:08
Re: DBits - 16-bit and 8-bit arrays support. - by Anzipane! - 14.06.2011, 13:11
Re: DBits - 16-bit and 8-bit arrays support. - by MrDeath537 - 14.06.2011, 13:22
Re: DBits - 16-bit and 8-bit arrays support. - by MrDeath537 - 14.06.2011, 13:46
Re: DBits - 16-bit and 8-bit arrays support. - by Double-O-Seven - 14.06.2011, 13:54
Re: DBits - 16-bit and 8-bit arrays support. - by ylleron - 14.06.2011, 14:20
Re: DBits - 16-bit and 8-bit arrays support. - by MrDeath537 - 14.06.2011, 14:23
Re: DBits - 16-bit and 8-bit arrays support. - by Double-O-Seven - 14.06.2011, 14:29
Re: DBits - 16-bit and 8-bit arrays support. - by GangsTa_ - 14.06.2011, 15:56
Re: DBits - 16-bit and 8-bit arrays support. - by ZeQualX - 14.06.2011, 18:04
Re: DBits - 16-bit and 8-bit arrays support. - by MrDeath537 - 14.06.2011, 21:20
Re: DBits - 16-bit and 8-bit arrays support. - by Lorenc_ - 15.06.2011, 08:59
Re: DBits - 16-bit and 8-bit arrays support. - by leong124 - 15.06.2011, 09:21
Re: DBits - 16-bit and 8-bit arrays support. - by RyDeR` - 15.06.2011, 09:52
Re: DBits - 16-bit and 8-bit arrays support. - by leong124 - 15.06.2011, 11:59
AW: DBits - 16-bit and 8-bit arrays support. - by Forbidden - 15.06.2011, 12:39

Forum Jump:


Users browsing this thread: 4 Guest(s)