Skip to content

Instantly share code, notes, and snippets.

View elixirdada's full-sized avatar
:electron:
🥇LaLa

elixirdada

:electron:
🥇LaLa
View GitHub Profile
@elixirdada
elixirdada / calcChecksum.rb
Created November 5, 2018 20:55 — forked from trdev7/calcChecksum.rb
This Ruby file includes Ruby functions that Luhn algorithm is implemented. checkLuhn1 returns value if current barcode(including check digit) validates. checkLuhn2 returns value that current barcode join its checkdigit as suffix.
def sumLuhn (barcode, nParity)
checksum = 0
for i in 0..barcode.length - 1
nDigit = barcode[i].to_i
if nParity == i % 2
nDigit = nDigit * 2
end
checksum = checksum + nDigit / 10 + nDigit % 10
end
return checksum % 10
@trdev7
trdev7 / division_bignumber.c
Last active December 24, 2019 13:16
This application is C console application that substraction, division and remainder between two bigNumbers is implemented.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef signed short int_least16_t;
// swapping two charaters
void swap( char* a, char* b ) {
char p = *a;
*a = *b;
@trdev7
trdev7 / calcChecksum.rb
Last active December 24, 2019 13:15
This Ruby file includes Ruby functions that Luhn algorithm is implemented. Function ,"checkLuhn1 check if current barcode(included check digit) validates. Function, "checkLuhn2" returns value that current barcode join with its checkdigit as suffix. /********************************************/ [note] Here, I have used Bitwise Operator instead o…
def sumLuhn (barcode, nParity)
checksum = 0
for i in 0..barcode.length - 1
nDigit = barcode[i].to_i
if nParity == ( i & 1 ) # i % 2
nDigit = ( nDigit << 1 ) # nDigit * 2
end
checksum = checksum + nDigit / 10 + nDigit % 10
end
return checksum % 10