Hot answers tagged

3 votes
Accepted

Question about binary search. Please help!

Even or odd, it doesn't really matter. The point is that you are dividing the list approximately in half, give or take. If the split doesn't occur exactly at the middle (odd number of elements), it ...
user avatar
  • 63.1k
3 votes
Accepted

I have a doubt about binary code

That's because it is case sensitive. Uppercase, "B" ascii value "66", binary "01000010" (this should be the value shown in lecture on stage). Lowercase, "b" ascii value "98", binayr "01100010". The ...
user avatar
  • 1,359
2 votes

How is the determination made as to whether a binary number is negative or positive?

Your calculation doesn't seem to work because you are only looking at 4 bits. A 4-bit signed integer can only have the range of -8 to 7 -(2^3) to 2^3 - 1. The leftmost bit is reserved for the 'sign' (...
user avatar
  • 18.3k
2 votes
Accepted

Binary Notation

The binary numbering system has powers of 2 while the decimal numbering system has powers of 10. For example, the decimal value 548 is actually (8 x 1) + (4 x 10) + (5 x 100) or (8 x 10^0) + (4 x ...
user avatar
  • 17.4k
2 votes
Accepted

How do I write words and sentences in Binary?

Each character is represented in ASCII. And each ASCII code can be represented in binary code. The space character is also represented in ASCII. So the sentence hello world would be ...
user avatar
  • 7,326
2 votes
Accepted

Binary Search Problems

You have a naming conflict with the previously defined function bsearch() in stdlib. Try changing the name of your bsearch() function to something like binsearch() and recompile. If this answers ...
user avatar
  • 63.1k
1 vote
Accepted

cs50 pset3 binary search

You are getting this error message because, apparently the compiler couldn't find the main function in your program. Most probably you are compiling your code like this: make helpers the compiler ...
user avatar
1 vote
Accepted

Binary search implementation help please

Binary search means: You have a search interval, with left and right boundary. Is the interval empty? Yes => :( Value not found No => keep doing Calculate the middle index of the interval You ...
user avatar
  • 20.7k
1 vote

Recursive binary function returns error: control reaches end of non-void function

Your binarysearch function follows this logic: if (something) { if (something_else) { else { /* ... */ } /* **ERR:NOTHING_IS_RETURNED** */ // Here you must add a ...
user avatar
  • 1,223
1 vote
Accepted

pset 3 Binary search

First - think about what a segmentation fault is. It happens when you try to access memory that doesn't belong to you. https://stackoverflow.com/questions/2346806/what-is-a-segmentation-fault Try ...
user avatar
1 vote
Accepted

Week 3 Binary Search Video Short question

in case we have a single element left in the array, max and min would be equal. the midpoint is calculated, and we check whether array[midpoint] is equal to the value we're looking for. if the ...
user avatar
  • 17.4k
1 vote
Accepted

Binary search. What's wrong?

while (n > 0) When would "n" ever not be greater than zero? You'll never leave the loop, never return false. if else is this: if(true) { do this if true } else { do this if false } if ...
user avatar
  • 186
1 vote
Accepted

grasping turning Decimal notation to Binary

To convert a number from decimal notation to binary you have to make a series of integer divisions by two and note the reminder. You stop when the division has as result 0. Let's start with a small ...
user avatar
  • 7,326
1 vote
Accepted

how do we know if the user is trying to talk about the number 65 or the letter "A"

Well, as the programmer, you should know what type of input you need to take from the user (e.g., you wanna take a char, a string, an int, etc) then you use a function maybe from the C standard ...
user avatar
  • 17.4k
1 vote

Binary Notation

In any number system, only certain amount of symbols are used to represent data. This 'certain amount' is known as the base or the radix. For example, in Decimal Number System, we are allowed to use ...
user avatar
  • 3,316

Only top scored, non community-wiki answers of a minimum length are eligible