sprintf()
Brought to you by:
jmarshall
From: ET T. <et...@mi...> - 2001-09-19 04:39:07
|
Disregard my last message. Can anyone tell me what is wrong with the following:- ---- unsigned long ix = 2220000; // a 32-bit variable char hexStr[100]; MemSet(hexStr, 100, 0); memset(hexStr, 0, 50); StrIToH(hexStr+StrLen(hexStr), (ix >> 24) & 0xff); hexStr[StrLen(hexStr)] = ':'; StrIToH(hexStr+StrLen(hexStr), (ix >> 16) & 0xff); hexStr[StrLen(hexStr)] = ':'; StrIToH(hexStr+StrLen(hexStr), (ix >> 8) & 0xff); hexStr[StrLen(hexStr)] = ':'; StrIToH(hexStr+StrLen(hexStr), (ix) & 0xff); hexStr[StrLen(hexStr)] = ':'; WinDrawChars(hexStr, StrLen(hexStr), 5, 20); ---- The output was 00000000:00000021:000000DF:000000E0. The prefixed zeros are mysterious, anyway, that aside, shouldn't it be 000000E0:000000DF:00000021:00000000 since motorola dragonball is big-endian? ---- unsigned long ix = 2220000; // a 32-bit variable char hexStr[100]; MemSet(hexStr, 100, 0); sprintf(hexStr, "%x:%x:%x:%x", (ix >> 24) & 0xff, (ix >> 16) & 0xff, (ix >> 8) & 0xff, ix & 0xff); WinDrawChars(hexStr, StrLen(hexStr), 5, 20); ---- The output was 0:0:0:21. I don't understand why. Could be that I was using sprintf() the wrong way?. |