부울 배열은 1에 대해 true이고 0에 대해 false입니다. 8은 거짓 거짓 거짓 true로 표시됩니다. 인덱스 3에서 6은 거짓, 참, 참일 것입니다. 또한 pow()를 사용하지 않고이 작업을 수행하려고합니다. 메서드는 정수로 10 진 표현을 반환합니다. 내가 지금까지 무엇을 가지고C++ 부울 배열로 표현 된 이진수의 정수로 10 진수 값을 반환하는 메서드
: 도움을
int Binary::binaryToInteger(bool *binaryArray, int size)
{
Something that will keep track of the index and something that will keep track of
the amount I need to multiply by added to a total and an if else that will take care
of true or false
return total;
}
감사합니다!
가능한 중복 http://stackoverflow.com/questions/10949491/fast-way-to- 이진수 - 십진수 변환) – CoryKramer
입력 배열에 숫자의 부호가 표시되어 있습니까? –
@ MarkB : int의 부호는 가장 높은 비트에 있습니다. 따라서 배열 크기가'<= numeric_limits :: digits'이면 배열은 부호없는 숫자를 나타냅니다. 배열의 크기가'== numeric_limits :: digits + 1'이면 마지막 배열 요소는 부호를 지정합니다. 'numeric_limits :: digits'는 부호 비트를 계산하지 않습니다. –