reticentroot
reticentroot

Reputation: 3682

How does a computer tell the difference between a float binary values and an integer binary value?

I was working on some binary practice problems when I noticed something interesting. How does a computer differentiate between binary values. For instance 13 in binary is 1101 and 0.8125 is also 1101 in binary. Since their binary values are the same, how does a computer know which is which. Or if I were converting it back to base 10, how would I know if the number was originally 13 or 0.8125?

Upvotes: 1

Views: 336

Answers (3)

Sankalp
Sankalp

Reputation: 1

Data Type is the answer. Computer looks for the datatype.

If binary value is 1101 and data type mentioned when declaring the variable was integer, then it will be 13. If data type mentioned was float, then it will be 0.8125. If the data type mentioned was char, then 13 would be the ascii value of the character.

I hope you understood what I explained.

Upvotes: 0

Buddy
Buddy

Reputation: 11028

The binary value in a nylocation in memory could be anything (a number, a program instruction, a floating point number, etc)... the program has to know what type to expect at that location.

Upvotes: 1

Amit
Amit

Reputation: 46323

The computer doesn't care about the "meaning" of the binary values till the point you instruct it to use it. When you do that, you explicitly "tell" the computer what the meaning is.

Upvotes: 2

Related Questions