File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
02. Algorithms/08. Strings/09. Checksum Calc Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ // 16bit binary adder with carry
2+ #include < iostream>
3+ using namespace std ;
4+
5+ uint16_t b16_adder (uint16_t a,uint16_t b)
6+ {
7+ uint32_t total32=0 ;
8+ total32=a+b;
9+ uint16_t rem=(total32>>16 );
10+ uint16_t total16=(total32);
11+ uint16_t real_total=(total16+rem);
12+
13+ return real_total;
14+ }
15+
16+ // pointer to data array and array size
17+ uint16_t checksum_ans16 (uint16_t *arr,uint data_size)
18+ {
19+ uint sz=((data_size%2 )>0 ?data_size+1 :data_size);
20+ uint16_t current_ans=0 ;
21+ int x=0 ;
22+ while (x<(sz/2 ))
23+ {
24+ uint16_t temp_ans=0 ;
25+ uint16_t no=(arr[x]);
26+ temp_ans=b16_adder (current_ans,no);
27+ current_ans=(uint16_t )temp_ans;
28+ }
29+ x++;
30+ return (uint16_t )(~current_ans);
31+ }
You can’t perform that action at this time.
0 commit comments