You are here:

C++/problem

Question
how can i convert binary number to decimal using forloop

Dear Rishi:

First of all, all numbers on the computer are represented in binary, normally.  You have to tell the compiler what format you want to show numbers.

I also expect this is a homework problem.  But I want to help you.

So I will frame the question so I can answer it.  Represent an integer in a binary representation using an array of integers.  You can modify this program to use an array of characters if you want and then convert each integer (1 or 0) to a character (1 or 0) in the for loop:

int D = 111 ;
int B [ 8 ] ;
for ( int i = 0 ; i < 8 ; ++ i )
{
B [ 7 - i ] = D % 2 ;
D /= 2 ;
}

C++

Volunteer

Titus B. Ledbetter, Jr.

Expertise

C , MFC, Object Oriented, Artificial Intelligence

Experience

I have over ten years experience in the field of Computer Science, five years experience developing C/C++. I recently wrote a chess program using Object Oriented, C++, MFC.

Education/Credentials
Master's Degree Computer Science from Johns Hopkins