Page 2 of 2

Re: Bit field support in PB Structures.

Posted: Sun Nov 23, 2014 7:23 am
by wilbert
Thunder93 wrote:I don't know if there's a better way to unset and set. However, here's what I have..
Don't know what is better but here's another way.

Code: Select all

Macro BitSet(var, bit)
  var | (1 << bit)
EndMacro

Macro BitReset(var, bit)
  var & ~(1 << bit)
EndMacro

Macro BitToggle(var, bit)
  var ! (1 << bit)
EndMacro

Macro BitGet(var, bit)
  (var >> bit) & 1
EndMacro


; *** test ***

Structure myStruct
  bitfields.w
  long.l
EndStructure  

Global a
Global b.myStruct

a = -1

BitReset(a, 2)
BitSet(b\bitfields, 1)

Debug BitGet(a, 1)
Debug BitGet(a, 2)

Debug BitGet(b\bitfields, 1)
Debug BitGet(b\bitfields, 2)

BitToggle(a, 1)
Debug BitGet(a, 1)

BitToggle(a, 1)
Debug BitGet(a, 1)

Re: Bit field support in PB Structures.

Posted: Tue Apr 19, 2016 7:00 am
by idle
made an initial equivalent to c bit fields, with some limitations.
http://www.purebasic.fr/english/viewtop ... 12&t=65518

Re: Bit field support in PB Structures.

Posted: Tue Apr 19, 2016 11:47 am
by NicknameFJ
Thorium wrote: -copy or move a subset of the bit field

@Thorium:

Take a look at my CopyBitField Procedure in the german forum if you need it.

Look here

OK, you´re right, a native command would be great.


NicknameFJ