hexa to binary code

code for hexa to binary number

Page 1 of 1

1 Replies - 639 Views - Last Post: 14 April 2009 - 02:10 PM Rate Topic: -----

#1 gonemadwithcomputers   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-April 09

hexa to binary code

Posted 14 April 2009 - 01:37 PM

int main (int argc, char *argv[])
{
char buf[500];
int index = 499;
buf[index] = '\0';
int n;
n = -275;

int neg;
neg = 0;
if(n < 0) {
neg = 1;
n *= -1;
}

do {
int d;
d = n % 2;
buf[--index] = (char)(d + '0');

n = n >> 1;
} while( n > 0);

if(neg) {
buf[--index] = '-';
}

printf("%s\n", &buf[index]);
return 0;
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 14 April 2009 - 02:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: hexa to binary code

#2 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: hexa to binary code

Posted 14 April 2009 - 02:10 PM

It compiles fine for me (GNU GCC).

Do you have a specific question?

Or if you want to submit this piece of code, don't use the forum, go over to the Snippets section and post it.


P.S. [ code]Paste Your Code Between The Code Tags[ /code]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1