W
W
WTFAYD2017-10-16 19:34:38
C++ / C#
WTFAYD, 2017-10-16 19:34:38

How to set values ​​for a range of bits in a variable?

Hello!
It is required to make the bit values ​​equal to 1 in a certain range in a 64-bit unsigned long, leaving the remaining bits unchanged. For example, 0x000100100fe80010 should become 0xffffffffffffff , i.e. the range of fe in the number remains unchanged. Tell me how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2017-10-16
@15432

Set bit 15 to 1:
var |= (1 << 14);
Set bit 15 to 0:
var &= ~(1ul << 14);
Install as you requested:
var= 0x000100100fe80010ul | 0xffffffff00ffffful;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question