Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverse of number in binary

Tags:

algorithm

Suppose we have some arbitrary positive number x.

Is there a method to represent its inverse in binary or x's inverse is 1/x - how does one express that in binary?

e.g. x=5 //101
x's inverse is 1/x, it's binary form is ...?


2 Answers

You'd find it the same way you would in decimal form: long division.

There is no shortcut just because you are in another base, although long division is significantly simpler.

Here is a very nice explanation of long division applied to binary numbers.

ld

Although, just to let you know, most floating-point systems on today's machines do very fast division for you.

like image 69
Justin L. Avatar answered Oct 25 '25 01:10

Justin L.


In general, the only practical way to "express in binary" an arbitrary fraction is as a pair of integers, numerator and denominator -- "floating point", the most commonly used (and hardware supported) binary representation of non-integer numbers, can represent exactly on those fractions whose denominator (when the fraction is reduced to the minimum terms) is a power of two (and, of course, only when the fixed number of bits allotted to the representation is sufficient for the number we'd like to represent -- but, the latter limitation will also hold for any fixed-size binary representation, including the simplest ones such as integers).

like image 22
Alex Martelli Avatar answered Oct 25 '25 02:10

Alex Martelli