High Definition Standard Definition Theater
Video id : DJxEYOC8IRc
ImmersiveAmbientModecolor: #ba9899 (color 2)
Video Format : (720p) openh264 ( https://github.com/cisco/openh264) mp4a.40.2 | 44100Hz
Audio Format: 140 ( High )
PokeEncryptID: 8fe925af72468980c6f9a87deb164394971c29c194a253d618abbacfd380c0b25dff70ee5c6e711ad8e3fc3fe7b11d16
Proxy : woke-proxy.poketube.fun - refresh the page to change the proxy location
Date : 1752954665288 - unknown on Apple WebKit
Mystery text : REp4RVlPQzhJUmMgaSAgbG92ICB1IHdva2UtcHJveHkucG9rZXR1YmUuZnVu
143 : true
Magic Swap
 60 FPS video
2,137,436 Views • May 31, 2024 • Click to toggle off description
Twitch
Everything is built live on twitch
Twitch : bit.ly/3xhFO3E
Discord: discord.gg/ThePrimeagen
Spotify DevHour: open.spotify.com/show/4MLaDrQcQ5mi3rsnvWkwPt
Editor
All my videos are edited by Flip. Give him a follow! twitter.com/flipmediaprod

Join this channel to get access to perks:
youtube.com/channel/UC8ENHE5xdFSwx71u3fDH5Xw/join

Links
Linode: linode.com/prime
discord.gg/ThePrimeagen
Twitch: twitch.tv/ThePrimeagen
Insta: instagram.com/ThePrimeagen
Twitter: twitter.com/ThePrimeagen
VimRC & i3: github.com/ThePrimeagen/.dotfiles
Keyboard 15% off bit.ly/Prime360 USE CODE PRIME360

#coding #neovim #typescript #programming #vim #softwareengineering #codinglife #webdesign #webdevelopment #webdev #javascript #rustlang #rust #twitch #twitchstreamer #programmerhumor #codinghumor #software #softwareengineer #softwaredeveloper #softwaredevelopment
Metadata And Engagement

Views : 2,137,436
Genre: Science & Technology
License: Standard YouTube License
Uploaded At May 31, 2024 ^^


warning: returnyoutubedislikes may not be accurate, this is just an estiment ehe :3
Rating : 4.916 (1,596/74,844 LTDR)

97.91% of the users lieked the video!!
2.09% of the users dislieked the video!!
User score: 96.86- Overwhelmingly Positive

RYD date created : 2025-07-19T16:38:11.63936Z
See in json

1,426 Comments

Top Comments of this video!! :3

@ThePrimeagen

1 year ago

Real World Application: ULPFEC -- datatracker.ietf.org/doc/html/rfc5109

I had to create tests around this at my job for Real Time Gaming at netflix. Forward error correction is really important in real time communications!

606 | 19

@ConsoleKits

1 year ago

I Iove the lesson that you can write a swap function in C, with a temp variable, and gcc with optimization turned on will change the solution to xor.

7.2K | 48

@erikberg2893

1 year ago

I had a coworker who had been coding since the 80s at my first job and he showed me this and my young professional mind exploded. It was amazing.

2.5K | 8

@ItsDan123

1 year ago

And that’s how we got through the great variable shortage unscathed.

2.5K | 13

@DrakePitts

1 year ago

def swap(a, b):
a = a XOR b
b = a XOR b
a = a XOR b

2.5K | 58

@TheChrisSimpson

4 months ago

GCC and most compilers will optimize the temp variable to a register. So just using a temp variable instead of explicit XOR is almost always better because of optimization, no extra memory actually gets used. XOR swaps use more cpu cycles.

27 | 0

@askerafaunov5424

1 year ago

I both understood this flawlessly and understood non of it at the same time

74 | 7

@Rafi-Riday

1 year ago

Similer like this :
a = a + b;
b = a - b;
a = a - b;

1.8K | 55

@playday3008

1 year ago

It's easy, just use x86 ASM instruction XCHG, which does swap of values in registers

359 | 29

@surinassawajaroenkoon6064

1 year ago

The hard part is when a junior developer has to read your code.

753 | 18

@user-kt0jl90sfwj8cb

11 months ago

Math seems like magic until you learn it and understand that it actually is magic.

78 | 1

@ananthshetty2746

1 year ago

This is very similar to swaping variables using operations that are inverse of each other like + and - or * and /. This happens because a xor b xor b = a. So in this xor acts like its own inverse

48 | 0

@igorfujs7349

11 months ago

This is the perfomance nightmare. 6 reads and 3 writes to memory. An optimized compiler can simply do it with
register x = load a
register y = load b
a = register y
b = register x

2 reads and 2 writes is all it takes.

85 | 9

@puncherinokripperino2500

1 year ago

(a xor b) xor b = a
(a xor b) xor a = b
basically, so it's easy to see
a' = a xor b
b' = a' xor b = (a xor b) xor b = a
a'' = a' xor b' = (a xor b) xor b' = (a xor b) xor a = b

91 | 3

@turanamo

1 year ago

This was one of the interview questions asked 20 years ago that got me into my professional career in Embedded Systems. I got it wrong and still got hired. lol!

8 | 1

@AntonErholt

1 year ago

Corner case: If a and b are pointers to the same value and the swap is done by: 3x of *a ^= *b; then both a and b will point to 0.

141 | 9

@mantictac

1 year ago

Ah, something you absolutely should not do in your code unless you're using a compiler from the 80s.

187 | 11

@DLCSpider

1 year ago

It's also a terrible algorithm.

It's buggy: If a and b refer to the same memory location, you just zero that memory location.
It's slower: modern CPUs are superscalar and they like to execute independent instructions in parallel. The xor variant is inherently scalar, the one with the temp register is not.

41 | 12

@dmitrirodzik

1 year ago

Basically first XOR works as difference between bits in two numbers. 0 - no difference, 1 - yes difference. Then we just apply it to B. When we apply it we turn B to A initial value. Then to derive the B initial value we apply the same difference to A value which is now stored in B.

13 | 4

@Badspot

8 months ago

This will be really useful the next time I'm completely 100% out of memory and also my cpu only has 2 registers.

5 | 1

Go To Top