Thread: conversion
View Single Post
  #6 (permalink)  
Old March 18th, 2004, 07:05 AM
gbilios gbilios is offline
Authorized User
 
Join Date: Mar 2004
Posts: 33
Thanks: 0
Thanked 1 Time in 1 Post
Default

one point though, in two's complement, a negative binary number is first converted to positive, and then a 1 is added to the rightmost bit. The code you rephrased does not add a one to the rightmost bit of the result:

int count;
int num = 0;
for (count = 0; count < SIZE; ++count)
{
    num *= 2; // shift left.
    num += (binary[count] == '1')? 0 : 1;
} // end for



George N. Bilios
Reply With Quote