## Could somone explain how to use bit, bit set etc?

New to FreeBASIC? Post your questions here.
fxm
Posts: 9997
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

### Re: Could somone explain how to use bit, bit set etc?

olympic sleeper wrote:I still don't know what the 1ull in Print Hex(BitSet(1ull, 63)) represents.

'ull' is a suffix to add at the end of an integer literal to specify the integer size.
Integer literals ending with 'ull' are considered as unsigned 64 bit integers (ULongInt).

See the Literals documentation page.
fxm
Posts: 9997
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

### Re: Could somone explain how to use bit, bit set etc?

olympic sleeper wrote:Thinking it further I'm not sure a new user will realise that 5 (decimal) is &b00000101 which is why resetting the least significant bit (0) will produce 4. I'd forgotten that!

Can some simpler examples be added? something like

bitsset(&b10001,2) = &b10101
bitreset(&b10001,0) = &b10000

Done.
MrSwiss
Posts: 3636
Joined: Jun 02, 2013 9:27
Location: Switzerland

### Re: Could somone explain how to use bit, bit set etc?

olympic sleeper wrote:I have a feeling my issue was that these operate on bits, but the examples don't use bits (binary) they use decimal or hex,not exactly obvious hex either.
That should actually be obvious, because the smallest memory allocation unit
is a U/Byte, aka: 8 Bits (you cannot allocate bit-wise, only byte-wise).

re HEX: it's just a short-hand way, to express BIN, &h0F = &b00001111

olympic sleeper wrote:I wonder how many new users will know what bit 63 (binary) actually equates to in anything, and to be honest I still don't know what the 1ull in Print Hex(BitSet(1ull, 63)) represents.
This isn't actually a 'beginners' topic, but rather meant to be for 'advanced users',
where some knowledge (DEC, HEX, BIN) is considered, required know-how.
bfuller
Posts: 339
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

### Re: Could somone explain how to use bit, bit set etc?

Not sure I really get the original question but fundamentally, in any data, if you want to SET a specific bit as a status flag then "OR" it with the same data with that particular bit set to 1 and all other bits 0. If you want to CLEAR the status flag bit, then "AND" with the appropriate bit at 0 and all other bits set to 1.
MrSwiss
Posts: 3636
Joined: Jun 02, 2013 9:27
Location: Switzerland

### Re: Could somone explain how to use bit, bit set etc?

bfuller wrote:Not sure I really get the original question ...
Nope, I think, that you misunderstood the question.

The question referres to FB's internal #Define's:
Bit(any_size_integer, bit_index)
BitSet(any_size_integer, bit_index)
BitReset(any_size_integer, bit_index)
They sort of simplify your proposed method, because there are no *masks required.

*mask = predifined, to manipulate a fixed length variable, with AND or OR.
olympic sleeper
Posts: 41
Joined: Jun 07, 2020 15:47

### Re: Could somone explain how to use bit, bit set etc?

fxm wrote:
olympic sleeper wrote:I still don't know what the 1ull in Print Hex(BitSet(1ull, 63)) represents.

'ull' is a suffix to add at the end of an integer literal to specify the integer size.
Integer literals ending with 'ull' are considered as unsigned 64 bit integers (ULongInt).

See the Literals documentation page.

Sorry I am still confused, its ull for unsigned long int? Any idea why it isn't uli? Or does the last l stand for literal? While on the subject are all long ints 64 bit or does that depend on the underlaying (32/64) bit architecture?

Thanks for the updates to the manual I feel they help a lot.
SARG
Posts: 1165
Joined: May 27, 2005 7:15
Location: FRANCE

### Re: Could somone explain how to use bit, bit set etc?

olympic sleeper wrote:Sorry I am still confused, its ull for unsigned long int? Any idea why it isn't uli? Or does the last l stand for literal? While on the subject are all long ints 64 bit or does that depend on the underlaying (32/64) bit architecture?

unsigned long long....
paul doe
Posts: 1334
Joined: Jul 25, 2017 17:22
Location: Argentina

### Re: Could somone explain how to use bit, bit set etc?

olympic sleeper wrote:...
While on the subject are all long ints 64 bit or does that depend on the underlaying (32/64) bit architecture?
...

Only FreeBasic's integer data type size changes depending on the architecture. This table should prove invaluable if you have prior experience with C/want to port some code:

C/C++ vs. FreeBASIC integer data type comparison
MrSwiss
Posts: 3636
Joined: Jun 02, 2013 9:27
Location: Switzerland

### Re: Could somone explain how to use bit, bit set etc?

olympic sleeper wrote:While on the subject are all long ints 64 bit or does that depend on the underlaying (32/64) bit architecture?
It's LongInt (one word) and yes, they are fixed size (64 bit).
More info on those integer data-types, is found in the FB-reference.