shithub: sl

ref: 24a71723ffbe92ccbdc088a078d776fb869b52ca
dir: /3rd/mp/u16.c/

View raw version
#include "platform.h"
#include "mp.h"

#define between(x,min,max)	(((min-1-x) & (x-max-1))>>8)

int
enc16chr(int o)
{
	int c;

	c  = between(o,  0,  9) & ('0'+o);
	c |= between(o, 10, 15) & ('A'+(o-10));
	return c;
}

mpdigit
dec16chr(int c)
{
	int o;

	o  = between(c, '0', '9') & (1+(c-'0'));
	o |= between(c, 'A', 'F') & (1+10+(c-'A'));
	o |= between(c, 'a', 'f') & (1+10+(c-'a'));
	return o-1;
}