converting Binary Numbers in to decimal numbers

前端 未结 6 776
情歌与酒
情歌与酒 2021-01-28 23:42

I need a program to convert Binary numbers into Decimal number in Java or in C++.

is there some one who can help me.

6条回答
  •  半阙折子戏
    2021-01-29 00:29

    Algorithmically (in c/c++):

    const char* binary = "110010101011";
    int decimal = 0;
    
    while ( *binary ) 
    {
        decimal*=2;
        decimal+=*binary-'0';
        binary++ ;
     }
    

    Note that this doesn't handle invalid characters (anything other than binary digits).

提交回复
热议问题