-5

I want to write program (at the moment I don't have any code), which should do the following:

  1. Take from user string containing binary number,
  2. Convert it to unsigned int and signed int,
  3. Return the result to the user.

How can I implement the second activity? I'm looking for any help.

GingerPlusPlus
  • 5,336
  • 1
  • 29
  • 52

1 Answers1

1

I suggest you develop your own algorithm using pen and paper:

For each digit in string do:
  value = digit - '0'; convert from text to internal representation.
  binary number <<= 1; Move the existing bits left by one to make room.
  binary number |= value;  put the digit into the binary number.
  right shift string.
end-for.

Or you can write your own code, test it and debug it, then if you have any questions, post them (along with the code) as a new question.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154