Difference between revisions of "Intermediate C++ Game Programming Tutorial 23"

From Chilipedia
Jump to: navigation, search
(Video Timestamp Index)
(Video Timestamp Index)
Line 33: Line 33:
 
** XRGB 8-bit values are packed into a 32-bit word using <code>(x<<24u) | (r<<16u) | (g<<8u) | b)</code>
 
** XRGB 8-bit values are packed into a 32-bit word using <code>(x<<24u) | (r<<16u) | (g<<8u) | b)</code>
 
</div>
 
</div>
* Packing flag values into single integer parameter [https://youtu.be/WPMwq0qM8Kk?t=14m29s 14:29]
+
* Packing flag values into a single integer parameter [https://youtu.be/WPMwq0qM8Kk?t=14m29s 14:29]
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 
** Used in libraries such as the Windows API, DirectX, in STL
 
** Used in libraries such as the Windows API, DirectX, in STL

Revision as of 06:51, 26 November 2019

Bit twiddling is a lot of bullshit that is usually avoided when possible because it leads to ass code. Still, it is necessary in various situations, so you gotta learn this shit, and now is as good a time as any I guess.

Topics Covered

  • Bitwise AND (&), OR (|), and shift left/right (>> and <<)
  • Unary bitwise NOT/complement (~) and bitwise XOR (^)
  • Masking with & and combining with |
  • Packing and unpacking smaller data in larger types
  • Bit flags
  • Bitwise arithmetic optimizations

Video Timestamp Index

Tutorial 23

[Expand]
  • Introducing std::string ToBin(unsigned int n, int min_digits=0); to convert integers to their binary representation 0:15
  • Bitwise operators 1:50
  • Shifting operations 5:10
  • Packing and unpacking data 7:07
  • Example use case: The Color class in the Framework 12:20
  • Packing flag values into a single integer parameter 14:29
  • Advanced Bitwise operations 16:48
  • WORK-IN-PROGRESS

Homework

  • Figure out how the binary string formatter routine works
  • Figure out why x % 16 compiles to x & 0xF

The solution for the problems will not have its own video. Feel free to come on the discord and compare your answers with others, or to ask specific questions if you are having trouble understanding.

See also