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

Quote:
Originally Posted by ******
Посмотреть сообщение
There's a better argument for using the "DBIT_VAR" than the one even MrDeath537 gave, consider this code:

pawn Код:
Bit16_Get(arr, ++i);
Without using "DBIT_VAR" that code will not work correctly as "i" will actually be incremented twice.
But even with DBIT_VAR, "i" will get incremented twice! The first time when DBIT_VAR is assigned with "i" and a second time in the following code...

Making the Bit16_Get function as a stock function could solve this.

//Edit: I've tried my luck with nibble coding.^^
pawn Код:
#define Nibbles:%0<%1> \
    %0[((%1) + 8) >>> 3]

stock Nibble_Get (arr [], slot)
{
    new shamt = (slot & 7) * 4; // (slot % 8) * 4
    return ((arr [slot >>> 3] & (0x0F << (shamt))) >>> shamt);
}

stock Nibble_Set (arr [], slot, val)
{
    new
        shamt = (slot & 7) * 4, // (slot % 8) * 4
        s = slot >>> 3;
    arr [s] &= ~(0x0F << shamt); // Set target "cell" to 0.
    //arr [s] |= (val << shamt); // Using this, you have to make sure that val < 16 or other cells may get changed.
    arr [s] |= ((val & 0x0F) << shamt); // This looks more save to me.
}
I'm absolutely not sure if this works. I didn't test it.
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: 2 Guest(s)