Hamming Codes - How Data Corrects Itself

Sdílet
Vložit
  • čas přidán 25. 06. 2024
  • What happens if a mistake happens when data is transferred? With Hamming codes, we give data the ability to correct its own mistakes. Here, we explore how that works.
    0:00 Errors in Data
    0:56 Parity Bits
    2:14 Correcting Errors
    3:38 Hamming Code
    ***
    Spanning Tree is an educational video series about computer science and mathematics. See more at spanningtree.me
    To be notified when a new video is released, sign up for the Spanning Tree mailing list at spanningtree.substack.com/
    Spanning Tree is created by Brian Yu. brianyu.me/
    Email me at brian@spanningtree.me to suggest a future topic.

Komentáře • 62

  • @misiekeloo6114
    @misiekeloo6114 Před 3 lety +167

    But what if an error occurs in a parity beat?

    • @SpanningTree
      @SpanningTree  Před 3 lety +223

      Hamming Codes handle this case too! If there's an error in a parity bit, then that parity bit won't be correct when the data is received. And since the other parity bits will be correct (assuming at most a 1-bit error), we'll know that the parity bit needs correction.

    • @misiekeloo6114
      @misiekeloo6114 Před 3 lety +49

      Thank you, you are doing a really great job, keep it up :)

    • @aenetanthony
      @aenetanthony Před rokem +9

      @@SpanningTree Is it possible to build a way to detect two or more errors in the data? What is the limit of bits flipped, if it is possible?

    • @MichaelDarrow-tr1mn
      @MichaelDarrow-tr1mn Před rokem +8

      @@aenetanthony hamming codes can detect (but not correct) two bit errors

    • @reda29100
      @reda29100 Před rokem +3

      @@aenetanthony as mentioned in the vid, an error is likely to be just 1. 1 bit in how many? I would presume 100 in today's hardware. I'm not working with hard facts, pun intended, but O think math and probability can tell what is a reasonable amount of errors an X bytes of data ay hve with a confidence of say 99%.
      So technically, there could be 2, 3 and even all bits are mis-transmitted, bit statistically with today's hardware I think that's improbable.

  • @vivekagrawal4607
    @vivekagrawal4607 Před 3 lety +71

    Thanks Brian for all the work you do to help students :)

  • @hereigoagain5050
    @hereigoagain5050 Před rokem +40

    I don't need Hamming codes: my wife tells me when I'm wrong :) Excellent video. When you learn this in CS class, it is topic 3 of 4 in a 90 minute lecture to over 100 students.

    • @griffinshorts785
      @griffinshorts785 Před rokem +1

      How do you take CS class? Like is it in college?
      - Just a curious commenter

    • @superspartanman4480
      @superspartanman4480 Před rokem

      @@hereigoagain5050 Aw man do you know what a minimum spanning tree is?

  • @suikodin2501
    @suikodin2501 Před rokem +16

    Absolutely fantastic explanation! The progression and pace of the examples was perfect for me.

  • @jamesdaus
    @jamesdaus Před 4 lety +12

    Great video, thorough and visuals help a ton

  • @matrick1356
    @matrick1356 Před rokem +21

    6:18 there should be an addition/correction in phrasing here: "which of the bits was included in both the first bit third parity bits, but not the second bit?" the last data bit is correct since the second bit validates it. The error is in the bit where all of the parity bits is wrong

    • @mypaxa003
      @mypaxa003 Před rokem

      So that's why... Thank you.

  • @andrekim9223
    @andrekim9223 Před 9 měsíci +1

    The best video about hamming codes i have ever seen

  • @rabiaedaylmaz1198
    @rabiaedaylmaz1198 Před rokem +2

    I was reading The Art of Doing Science and Engineering: Learning to Learn by Richard Hamming. This video helped me a lot to understand how he explained in there, thank you!

  • @sid98geek
    @sid98geek Před rokem +9

    This channel is so underrated and deserving of so much praise!

  • @edl7176
    @edl7176 Před rokem +1

    That's so nice! You guys are the reason I watch youtube!

  • @sulavlalshrestha6683
    @sulavlalshrestha6683 Před 2 lety +4

    Great videos. Sad that I found the channel just now and not earlier.

  • @eduardoarteaga8402
    @eduardoarteaga8402 Před rokem +1

    I really like your videos. Thank you!

  • @OzanErenBilgen
    @OzanErenBilgen Před 8 měsíci

    Great video, amazing algorithm!

  • @sujitkumarsingh3200
    @sujitkumarsingh3200 Před rokem +3

    I had totally forgoten about this topic. Thanks for refreshing it.

  • @ananyagupta1409
    @ananyagupta1409 Před rokem +1

    Great! Bravo!

  • @dannywei6933
    @dannywei6933 Před 10 měsíci

    Great video!

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 Před rokem +1

    6:55 That efficiency comes at a cost, namely less robustness. Assuming the same characteristics storage/transmission medium, a block of 247 bits is 247/7 times more likely to have errors in it than a block of 7 bits. But you only have 8/3 times the parity bits to protect it.

  • @ludovicbouchard252
    @ludovicbouchard252 Před rokem +4

    does normal ram does this or is it integrated only in ECC ?

  • @KhmerKhmer-no9cm
    @KhmerKhmer-no9cm Před rokem +4

    Bit 👍

  • @xTasyDotes
    @xTasyDotes Před rokem +2

    its like sudoku but with extra steps (?)

  • @BS-bd4xo
    @BS-bd4xo Před rokem +2

    This is so amazingly cool.
    But what about the fact that cosmic rays can change a digit? Veritasium made an entire video about that. Does this not just fix that issue?

    • @warriorsabe1792
      @warriorsabe1792 Před rokem +1

      It significantly reduces the impact, but if, say, two cosmic rays hit and flipped two bits, it would not be guaranteed to help anymore. Plus, hamming codes can't be used constantly - you can't actually use the protected data as-is for a lot of things because the parity bits get in the way, meaning if one hits while the data is being used for something and unprotected, it's also vulnerable there. Luckily, it's a lot less likely for an externally triggered error such as from a cosmic ray to happen during the short window of it being used versus the longer periods of storage or transmission where the codes are employed, just as it's much less likely for multiple bits to get flipped in the same data unit.
      And one thing you can do to protect more is to break down your data into smaller such units, so that if multiple bits get flipped, they're more likely to be in separate chunks that can separately detect the single error, though that does cost you in the fact that the codes are less size-efficient for said smaller chunks.

  • @axiomfinity
    @axiomfinity Před rokem

    Parity bits that represent the octals value

  • @a10netmedtv
    @a10netmedtv Před rokem +4

    6:25
    I have a question, what if the error occured in the last bit in the right side ?
    Can this method detect it ?

    • @kasufert
      @kasufert Před rokem +6

      The last bit is checked by all three parity bits. Since flipping it wold make all three parity bits wrong, it could be corrected.

    • @a10netmedtv
      @a10netmedtv Před rokem +2

      @@kasufert thanks, that makes sense now!

    • @danielfarfudinov3193
      @danielfarfudinov3193 Před rokem +1

      This method only works for a single flipped bit, and the parity bits together can be read as a binary id of the erroneous flipped bit. In the big example at the end, you can see that the parity bits are in those specific places because all of them only have a single "1" in its' binary "spot" in the sequence - [1: 10000000, 2: 01000000, 3: 00100000, 4: 00010000, 5: 00001000, 6: 00000100, 7: 00000010, 8: 00000001]. After that, you can override 00000000 with every erroneous parity bit, and achieve for example an error in the seventh position: 11100000, if the first 3 parity bits are erroneous.
      This property also helps when the parity bit itself is incorrect, since the result from the combination would lead to the parity bit itself: 01000000.

  • @oldbadname3633
    @oldbadname3633 Před rokem +5

    Hamming code relies on the assumption that there are only two possible states: entirely correct or with one error, but increasing bit package size also increases likelihood of error, so isnt there a limit to how effective Hamming Code can possibly be?

    • @Joe_Payne
      @Joe_Payne Před rokem +1

      My assumption is that since for large numbers you only need a small % for error correction that you would also implement similar error correction bits designed for detecting two bit errors

    • @zanfur
      @zanfur Před rokem +3

      This video was a simplification; hamming codes can be created that will correct up to N flipped bits (and, in general, detect 2N errors even if it can't fix them).

  • @Labib_1453
    @Labib_1453 Před měsícem

    was it the rigth MSB & LSB??

  • @josephsalviaii9183
    @josephsalviaii9183 Před rokem +2

    Cool video, just found it. What if the parity bit is flipped, would that get corrected?

    • @SunnySingh-ry4qs
      @SunnySingh-ry4qs Před rokem +1

      For that you'll need parity parity bits to correct parity bits, and to keep a check on those parity parity bits you'll need parity parity parity bits. Therefore i work as construction worker and not in an IT field.

    • @danielfarfudinov3193
      @danielfarfudinov3193 Před rokem +5

      @@SunnySingh-ry4qs The channel owner explained it above. If a parity bit is flipped, and therefore shows an error, every other parity bit will still be correct, therefore we can conclude that the error is not in the used data, but in the parity bit that shows an error
      Edit: This whole thing works because if the data has an error in it, there is always more than a single parity bit that will show an error.

  • @franchello1105
    @franchello1105 Před rokem +1

    Is this TCP/IP layer's responsibilylty?

  • @dhruvo100
    @dhruvo100 Před rokem

    What if there are more than one bit flipped? Then the parity bit with wont detect the problem?

    • @MichaelDarrow-tr1mn
      @MichaelDarrow-tr1mn Před 20 dny +1

      let's take the example 0110011.
      both bits 6 and 7 are flipped. we see 0110000.
      if we try to correct it we end up erroneously believing the correct result is 1110000, which encodes the data [1000] instead of [1011] that is originally encoded.

    • @dhruvo100
      @dhruvo100 Před 20 dny

      @@MichaelDarrow-tr1mn thanx

  • @poglin_or_smh
    @poglin_or_smh Před rokem

    2 bit corruption is very rare guys
    like even 1 bit error is stupidly rare

  • @tinypileofpolydimethylsiloxane

    At what point does it become more efficient to send the 4 data bits twice? This method only saves 1 bit, but i bet all this checking takes some computing power. I bet the extra electricity cost will more expensive then sending 4 correction bits every 4 data bits as opposed to 3.

    • @nicospadoni5328
      @nicospadoni5328 Před 10 měsíci

      You would have to send out three times, because otherwise you won't know which one is the wrong one

  • @Last-Tap
    @Last-Tap Před rokem

    Make more videos

  • @crelos3549
    @crelos3549 Před rokem +1

    It's like computer cancer

  • @PlaylistsM
    @PlaylistsM Před rokem

    ?

  • @roymallard
    @roymallard Před rokem

    is a parity bit sort of like a chicken mcnugget?

  • @hitarthk
    @hitarthk Před rokem +1

    What happens if 2 bits are flipped? Does the algorithm handle it gracefully?

    • @ninonook677
      @ninonook677 Před rokem

      It’s aware that there 2 errors, but not where.

    • @MichaelDarrow-tr1mn
      @MichaelDarrow-tr1mn Před 20 dny

      @@ninonook677 the one described just erroneously corrects it to a different state.