Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Decimal to Binary Conversion

Status
Not open for further replies.

km

Junior Member level 3
Junior Member level 3
Joined
May 26, 2004
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
322
I found this C program from internet:-

void d2b(unsigned int x, int *c)
{
int i;
for(i=0;i<=15;i++)
*(c++)=(x>>i) & 0x1;
}

For the bolded line, what does it mean? Can anyone please guide me?
 

c is a pointer to an Array of ints and the number to be converted is in x.
(x >> i) & 0x1; the number is shifted right i times and andded with 1.
*(C++) = the result is assigned to the array and the array index is incremented.
If x = 20, you would end up with
c[] = {0,0,1,0,1}; in the array.
The only purpos I can see for this is to print out the number in binary?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top