Archive for the ‘Conversions’ Category

Unsigned long long (uint64) to string (ulltostr)

Here is the code snippet which does conversion from unsigned long long (uint64) to
string/ascii/char *. 
it takes input as unsigned long long (uint64), converts it to string, it takes care of the base also.
example usage of function ulltostr is: ulltostr(1023234343453553, ptr, 10);
here is the code snippet….
 

 
#include <stdio.h>
 
#ifdef _MSC_VER
typedef unsigned __int64 uint64;
#else
typedef unsigned long long uint64
#endif
 
char *ulltostr(uint64 [...]

Continue Reading..
Posted in C Tidbits, Conversions

Unsigned long to string (ultostr)

Here is the code snippet which does conversion from unsigned long to string/ascii. There are library functions exists (ltostr, itoa) to integer to ascii, but there is no library function exists for unsigned long to ascii/string. ltostr converts signed long to string/ascii.
 

char *ultostr(unsigned long value, char *ptr, int base)
{
unsigned long t = 0, [...]

Continue Reading..
Posted in C Tidbits, Conversions

Binary to decimal

Binary System:
Base: 2
Digits: 0, 1
Example: 27 (decimal) = 11011 (binary)
Decimal System:
Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Binary 2 Decimal conversion Example
Transform 110101 (binary) into decimal number
111001 = 1*(2^5)+ 1*(2^4) + 1*(2^3) + 0*(2^2) + 0*(2^1) + 1*(2^0) = 32 + 16+ 8 +0 +0+1 = 57

int convert_bin2dec(char *binstring)
{
int [...]

Continue Reading..
Posted in Uncategorized