betomp.c

来自「这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易」· C语言 代码 · 共 41 行

C
41
字号
#include "os.h"#include <mp.h>#include "dat.h"// convert a big-endian byte array (most significant byte first) to an mpintmpint*betomp(uchar *p, uint n, mpint *b){	int m, s;	mpdigit x;	if(b == nil)		b = mpnew(0);	// dump leading zeros	while(*p == 0 && n > 1){		p++;		n--;	}	// get the space	mpbits(b, n*8);	b->top = DIGITS(n*8);	m = b->top-1;	// first digit might not be Dbytes long	s = ((n-1)*8)%Dbits;	x = 0;	for(; n > 0; n--){		x |= ((mpdigit)(*p++)) << s;		s -= 8;		if(s < 0){			b->p[m--] = x;			s = Dbits-8;			x = 0;		}	}	return b;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?