Комментарии:
This js also really useful for using less space for many bools.
Im a games programmer, and whenever i want to save a struct representing a state to a file, or send it over a network, i create an "optimized" version of that struct for the state, and send that over the wire. The optimized version can turn each 8 bools into just a single byte with bit masking.
This is a technique called bit packing, but it uses bit masking to write and read the bools back and forth from the optimized struct.
Nice roundup. I guess one thing I'd expect you to have talked about is the requirement to shift in some bit mask scenarios. Example: you have a uint16_t and you want to get hold of the literal value of the MSB, but not retain its binary weighting. If that makes sense.
Ответитьcan you expand on how a mask can replace if conditions? my mind is blown
ОтветитьThanks! this is very useful ❤❤ I used it in my c++ platformer game where if a tile has one way collision and you can't jump on it I can check for this by simply using the '&' operator, I can use bitmasks rather than making millions of variables that tell what a tile is capable of, this has compressed my tile maps size by 70% !!
ОтветитьI used bit masks a lot when programming my Atari 800 but haven't found much use for it since. I recently learned about the bitwise facilities in C++, disappointed that there doesn't seem to tie the bit patterns to real addresses. Looks to be all virtual.
I think bit-twiddling is fun but there doesn't seem to be as much call for as in the old days.
Literally u r proving the power of c...
ОтветитьAm really become ur fan...sir
ОтветитьWhat is the purpose of doing this?
ОтветитьtHANKS GOD HELPED A LOT
ОтветитьIn assembly/ML you do that all the time to set or clear certain bits in certain registers. Very clear tutorial. 👍
ОтветитьSir , tell us about debugging a project which is multi threaded and uses all IPC techniques and uses all process replacement mechanism..... In short a project which is using fully IPC techniques. How to debug that kind of projects .... specially the fork ,exec , ...ie debugging parent and child and thread same time
Ответитьvery informative, hard to find non-indian videos about C these days
ОтветитьI cant thank this guy enough. They are short and so in point. What would it look like if he was my professor teaching me?? I wish i could take it with him? I still dont understand bit minuplation well i don't if that makes me a bad programmer down the road in my computer science field.
Ответитьwhen i was practicing for job interviews, we had a saying "if you're stuck and don't know the answer, it's probably xor".
this advice got us through a lot of riddles, and I think it's the reason i got into my current job.
interviewers love xor.
Is there any codes which cure corona in Tamil nadu, India.. ??
ОтветитьLiterally implemented hardware bitmasks for my (FPGA) Gameboy ALU today!
They're also really useful for compiler optimizations, say for conditional assignment. Before conditional moves were around, you could run you condition check, setting a register to 1 if the condition is FALSE and to 0 otherwise, then decrement the register, and AND it to your assignment value. Given that 0 decremented is just a chain of 1s, it would act as an "enable" bitmask - letting all bits through - while 1 decremented (i.e. zero) would act as the "disable" bitmask - blocking all bits.
Given that branches tend to be expensive, I thought this was a really pretty way of avoiding them when I first found the pattern.
Awesome! Bit twiddling is so underrated these days, now that we have memory to spare and having 64+ boolean vars is common grounds. Although, readability and safefy should always be priority, it is good practice to keep bit manipulation fresh on your toolset. Great video as always!
Ответить