Langsung aja ke kode
/*******************************************************************
* Convert unsigned long long int to string.
* Params :
* - in : varible unsigned long long int that wil be converted [INPUT]
* - oBuff : buffer array [OUTPUT]
* - len_byte : length of buffer array [INPUT]
* return
* - len as length of buffer array
*
*/
int ullint2str(unsigned long long int in, unsigned char *oBuff, int len_byte) {
int len, i;
unsigned long long int tmp = 0x0L;
len = len_byte;
tmp = in;
for (i = len - 1; i >= 0; i--) {
oBuff[i] = tmp;
if (i != 0) tmp >>= 8;
}
return len;
}
Kode di atas diperuntukan untuk konvert long long integer ke string (array of char).
Lalu jika ingin sebaliknya, bisa perhatikan kode dibawah ini.
/************************************************************
* Convert string to unsigned long long int.
* Params :
* - sBuff : buffer array [INPUT]
* - len : length of buffer array [INPUT]
* return
* - ullint as unsigned long long int [OUTPUT]
*
*/
unsigned long long int str2ullint(unsigned char *sBuff, int len) {
unsigned long long int ullint = 0x0L;
int i;
for (i = 0; i < len; i++) {
ullint |= sBuff[i];
if (i<7)
ullint <<= 8;
}
return ullint;
}
Sekian dari saya, mohon maaf kalau tidak ada penjelasannya :)
Langsung dicoba aja :)
Wassalam
0 komentar:
Posting Komentar