⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 long2str.c

📁 操作系统源代码
💻 C
字号:
/* $Header: long2str.c,v 1.4 90/02/27 14:30:10 ceriel Exp $ *//* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". *//* Integer to String translator	-> base is a value from [-16,-2] V [2,16]	-> base < 0: see 'val' as unsigned value	-> no checks for buffer overflow and illegal parameters	(1985, EHB)*/#define MAXWIDTH 32char *long2str(val, base)	register long val;	register base;{	static char numbuf[MAXWIDTH];	static char vec[] = "0123456789ABCDEF";	register char *p = &numbuf[MAXWIDTH];	int sign = (base > 0);	*--p = '\0';		/* null-terminate string	*/	if (val) {		if (base > 0) {			if (val < 0L) {				long v1 = -val;				if (v1 == val)					goto overflow;				val = v1;			}			else				sign = 0;		}		else		if (base < 0) {			/* unsigned */			base = -base;			if (val < 0L) {	/* taken from Amoeba src */				register mod, i;			overflow:				mod = 0;				for (i = 0; i < 8 * sizeof val; i++) {					mod <<= 1;					if (val < 0)						mod++;					val <<= 1;					if (mod >= base) {						mod -= base;						val++;					}				}				*--p = vec[mod];			}		}		do {			*--p = vec[(int) (val % base)];			val /= base;		} while (val != 0L);		if (sign)			*--p = '-';	/* don't forget it !!	*/	}	else		*--p = '0';		/* just a simple 0	*/	return p;}

⌨️ 快捷键说明

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