How can I convert integers to binary or hexadecimal?
Answers were Sorted based on User's Feedback
Answer / sabarish
for decimal to hexa its very simple.
void main()
{
int a=10;
printf("%x",a); // returns the hexa decimal equivalent
}
| Is This Answer Correct ? | 14 Yes | 2 No |
Answer / 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 |
c program to manipulate x=1+3+5+...+n using recursion
Can you please explain the difference between strcpy() and memcpy() function?
Which are low level languages?
what is the use of getch() function in C program.. difference b/w getch() and getche()??
29 Answers HCL, IBM, Infosys, TCS, Wipro,
What are the commands should be given before weiting C Program i.e, Cd.. like
4 Answers IBM, Infonet, Satyam, Tech Mahindra,
what will be the output of this program? #include<stdio.h> #define cube(x) x*x*x void main() { int i,j=5; i=cube(j+3); printf("i=%d",i); }
write a C program, given number is double without using addt ion and multiplication operator?ex:n=6,ans=12,pls send me ans to goviseenu@gmail.com
1)what are limitations for recursive function? 2)write a program to read a text file and count the number of characters in the text file
program to get the remainder and quotant of given two numbers with out using % and / operators?
10 Answers College School Exams Tests, IBM,
What is the use of the restrict keyword?
What is hashing in c language?
Are the expressions * ptr ++ and ++ * ptr same?