Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How can I convert integers to binary or hexadecimal?

Answer Posted / sabarish

code to convert binary to decimal

void dec2bin(long decimal, char *binary)
{
int k = 0, n = 0;
int neg_flag = 0;
int remain;
int old_decimal; // for test
char temp[80];

// take care of negative input
if (decimal < 0)
{
decimal = -decimal;
neg_flag = 1;
}
do
{
old_decimal = decimal; // for test
remain = decimal % 2;
// whittle down the decimal number
decimal = decimal / 2;
// this is a test to show the action
printf("%d/2 = %d remainder = %d\n", old_decimal,
decimal, remain);
// converts digit 0 or 1 to character '0' or '1'
temp[k++] = remain + '0';
} while (decimal > 0);

if (neg_flag)
temp[k++] = '-'; // add - sign
else
temp[k++] = ' '; // space

// reverse the spelling
while (k >= 0)
binary[n++] = temp[--k];

binary[n-1] = 0; // end with NULL
}

Is This Answer Correct ?    4 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..

1895


How can a number be converted to a string?

1302


void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }

1706


What is methods in c?

1066


What is header file in c?

1053


pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)

2629


Explain #pragma statements.

1028


What is keyword with example?

1048


What are types of functions?

1028


What is optimization in c?

985


Can variables be declared anywhere in c?

1072


c program for searching a student details among 10 student details

2083


exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above

1100


Is it acceptable to declare/define a variable in a c header?

1099


When can a far pointer be used?

1007