Giter Site home page Giter Site logo

pvrtss / hamming-code Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 706 KB

Онлайн калькулятор кода Хэмминга

Home Page: https://pvrtss.github.io/hamming-code/

HTML 8.19% CSS 3.36% TypeScript 88.45%
react styled-components typescript coding-theory

hamming-code's Introduction

Калькулятор кода Хэмминга

Опробовать калькулятор можно нажав по ссылке

Алгоритмы

Кодирование

Алгоритм кодирования представлен ниже:

const conversionMatrix = [
  [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
  [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
  [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1],
  [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
];

export function encode(word: string) {
  const correctingBitsMap = [0, 1, 3, 7];
  const dataBits: any[] = word.trim().replace(/ +/g, "").split("");
  const correctingBits: number[] = [];
  correctingBitsMap.map((i) => dataBits.splice(i, 0, "0"));
  conversionMatrix.map((line) => {
    const prod: number[] = [];
    line.map((bit, index) => prod.push(bit * parseInt(dataBits[index], 2)));
    return correctingBits.push(prod.reduce((sum, elem) => sum + elem) % 2);
  });
  correctingBits.reverse();
  dataBits.forEach((item, i) =>
    correctingBitsMap.includes(i)
      ? (dataBits[i] = correctingBits.pop()?.toString())
      : (dataBits[i] = item)
  );
  return dataBits.join("");
}

Декодирование

// `conversionMatrix` используется из предыдущего алгоритма
export function decode(word: string) {
  const errorSyndrom: number[] = [];
  conversionMatrix.map((line) => {
    const prod: number[] = [];
    line.map((bit, index) => prod.push(bit * parseInt(word[index], 2)));
    return errorSyndrom.push(prod.reduce((sum, elem) => sum + elem) % 2);
  });
  errorSyndrom.reverse();
  const checksum = errorSyndrom.reduce((sum, elem) => sum + elem);
  return checksum ? parseInt(errorSyndrom.join(""), 2) - 1 : -1;
}

Проверка проверяющей способности

Находится в этом файле

hamming-code's People

Contributors

pvrtss avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.