计算机网络中,16位校验和的实现

本文详细介绍了如何在计算机网络中实现16位校验和的算法。通过读取文本文件中的每个字符,将字符转换为16进制,并与下一个字符组合形成双16进制数值,然后进行累加,最终得到校验和。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
struct M
{
	int hegiht;
	int low;
};
struct MM
{
	M m1;
	M m2;
};
MM add(MM g1, MM g2)
{
	MM demo;
	int f[4] = { 0 };
	int ff[4] = { 0 };
	int c1, c2, c3, c4;
	c1 = g1.m2.low + g2.m2.low;
	if (c1 >= 16) f[3] = 1;
	c2 = g1.m2.hegiht + g2.m2.hegiht;
	if (c2 >= 16) f[2] = 1;
	c3 = g1.m1.low + g2.m1.low;
	if (c3 >= 16) f[1] = 1;
	c4 = g1.m1.hegiht + g2.m1.hegiht;
	if (c4 >= 16)f[0] = 1;

/*	if ((c1 + f[0]) / 16) ff[3] = 1;
	demo.m2.low = (c1 + f[0]) % 16;
	
	if ((c2 + f[3] + ff[3]) / 16) ff[2] = 1;
	demo.m2.hegiht = (c2 + f[3]+ff[3]) % 16;
	
	if ((c3 + f[2] + ff[2]) / 16) ff[1] = 1;
	demo.m1.low = (c3 + f[2]+ff[2]) % 16;
	
	demo.m1.hegiht = (c4 + f[1]+ff[1
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值