기본 콘텐츠로 건너뛰기

8월, 2010의 게시물 표시

Data Conversions

Data Conversions By VGirish  | 28 Jun 2002 These are a few samples of data conversions which you can use for a quick reference Introduction Here are a few data conversions with small examples :- Decimal Conversions Decimal To Hex  Collapse // Use _itoa( ) function and set radix to 16. char hexstring[ 10 ]; int number = 30 ; itoa( number, hexstring, 16 ); // In hexstring is 1e. Hex To Decimal  Collapse // You can use strtol function and you can specify base. char * hexstring= " ABCDEF" ; char * p; int number = strtol(hexstring, &p, 16 ); // A function that does this bool HexToDecimal ( char * HexNumber, int& Number) { char * pStopString; Number = strtol (HexNumber, &pStopString, 16 ); return ( bool )(Number != LONG_MAX); } Decimal to time  Collapse char *DecToTime( float fTime, char *szTime) { int nHrs, nMin, nSec; fTime *= 3600 ; nHrs = ( int )fTime / 3600 ; nMin = ( int )(fTime - nHrs * 3600 ) / 60 ; nS