Esempio n. 1
0
/*****************************************
UnUnicodeHex(): Convert "ª" to hex.
Returns hex or -1 on error.
*****************************************/
int UnUnicodeHex(char* S)
{
  int v;
  if ((S[0] == '&') && (S[1] == '#') && (S[2] == 'x')
    && isxdigit(S[3]) && isxdigit(S[4]) && (S[5] == ';'))
  {
    v = Hex2Dec(S[3]) * 16 + Hex2Dec(S[4]);
    return (v);
  }
  return (-1);
} /* UnUnicodeHex() */
Esempio n. 2
0
void MACStrToBin( char *sz, uint8_t *pMAC )
{
	char *p;
	char c;

    uint8_t index = 0;
	uint8_t acc = 0;
	
	p = sz;
	
	while ( ( c = *p++ ) ) 
	{
		if ( ' ' == c ) {
			continue;
		}	

        if ( ( '-' == c ) || ( ':'== c )  )
		{
            pMAC[ index++ ] = acc;
            acc = 0;
        }
		else
		{	c = Hex2Dec(c);
            acc = ( acc * 16 ) + c;
		}
    }

    pMAC[ 5 ] = acc;
}
Esempio n. 3
0
void main(void)
{
	DDRC = 0xff;
	PORTC = 0xff;
	unsigned char ch,ch1;
	unsigned char buf[10];

	uart1_init();
	lcd_init();	
	lcd_char('*');
	
	init_i2c();
	
	WR_I2C(0,0x57);//Sec
    WR_I2C(1,0x59);//Min
	WR_I2C(2,0x11 | (1<<5)|(1<<6) );//Hr
    WR_I2C(3,1);//Day
	WR_I2C(4,0x31);//Date
    WR_I2C(5,0x12);//Month
	WR_I2C(6,0x99);//year
	
	while(1)
	{	
		ch = RD_I2C(0,0);//sec
		sprintf(buf,"\n\rSec = %02d",Hex2Dec(ch));
		uart1_transmit_string(buf);

		ch = RD_I2C(1,0);//min
		sprintf(buf,"\n\rMin = %02d",Hex2Dec(ch));
		uart1_transmit_string(buf);
	
		ch = RD_I2C(2,0);//hr
		sprintf(buf,"\n\rHr = %02d",Hex2Dec( ch & 0x1F ) );
		uart1_transmit_string(buf);
	
		ch = RD_I2C(3,0);//day
		sprintf(buf,"\n\rDay = %02d",Hex2Dec(ch));
		uart1_transmit_string(buf);

		ch = RD_I2C(4,0);//date
		sprintf(buf,"\n\rDate = %02d",Hex2Dec(ch));
		uart1_transmit_string(buf);
	
		ch = RD_I2C(5,0);//month
		sprintf(buf,"\n\rMonth = %02d",Hex2Dec(ch));
		uart1_transmit_string(buf);

		ch = RD_I2C(6,0);//year
		sprintf(buf,"\n\rYear = %02d",Hex2Dec(ch));
		uart1_transmit_string(buf);
		_delay_ms(1000);
	
	}
}
Esempio n. 4
0
  void Toolbox::UrlDecode(std::string& s)
  {
    // http://en.wikipedia.org/wiki/Percent-encoding
    // http://www.w3schools.com/tags/ref_urlencode.asp
    // http://stackoverflow.com/questions/154536/encode-decode-urls-in-c

    if (s.size() == 0)
    {
      return;
    }

    size_t source = 0;
    size_t target = 0;

    while (source < s.size())
    {
      if (s[source] == '%' &&
          source + 2 < s.size() &&
          isalnum(s[source + 1]) &&
          isalnum(s[source + 2]))
      {
        s[target] = (Hex2Dec(s[source + 1]) << 4) | Hex2Dec(s[source + 2]);
        source += 3;
        target += 1;
      }
      else
      {
        if (s[source] == '+')
          s[target] = ' ';
        else
          s[target] = s[source];

        source++;
        target++;
      }
    }

    s.resize(target);
  }
COleVariant CDataTypeConverter::HexM2OleVariant(CString strHexM)
{
	BYTE bt[255];
	short int len=strHexM.GetLength();
	short int length=0;
	short int intDec;
	for(int n=0,i=0;n<len-1;n+=2,i++)
	{		
		intDec=Hex2Dec(strHexM.Mid(n,2));
		bt[i]=char(intDec);
		length=i+1;
	}
	CByteArray m_Array;
	m_Array.RemoveAll();
	m_Array.SetSize(length);
	for(int i=0;i<length;i++)
		m_Array.SetAt(i,bt[i]);
	return COleVariant(m_Array);
}