How do you convert binary to decimal if the binary was 1.01? - binary

What is 1.01 binary in decimal?

Just remember we use positional numbering system.
1101 = 2^0 + 2^2 + 2^3 = 1 + 4 + 8 = 13
1.01 = 2^0 + 2^(-2) = 1 + 1/4 = 1.25

Positions to the left of the unit multiply by 2 each time. Positions to the right of the unit divide by 2 each time.
1 . 0 1
1×1 + 0×1/2 + 1×1/4 = 1 1/4

It's 1.25:
1 * 2^0 + 0 * 2^-1 + 1 * 2^-2
= 1 * 1 + 0 * 0.5 + 1 * 0.25
= 1 + 0.25
= 1.25

Related

How to solve functional equation?

I have functional equation
B(2z^4 + 4z^6 + 9z^8 + 20z^{10} + 44z^{12} + 96z^{14}) = (B(z))^4
I try to solve it using Maxima CAS :
(%i2) e: B(2*z^4 + 4*z^6 + 9*z^8 + 20*z^10 + 44*z^12 + 96*z^14) = (B(z))^4;
14 12 10 8 6 4 4
(%o2) B(96 z + 44 z + 20 z + 9 z + 4 z + 2 z ) = B (z)
(%i3) funcsolve (e,B(z));
expt: undefined: 0 to a negative exponent.
#0: rform(%r=[0,0])
#1: funcsol(%a=B(96*z^14+44*z^12+20*z^10+9*z^8+4*z^6+2*z^4) = B(z)^4,%f=B(z),l%=[])
#2: funcsolve(%a=B(96*z^14+44*z^12+20*z^10+9*z^8+4*z^6+2*z^4) = B(z)^4,%f=B(z))
#3: funcsolve(_l=[B(96*z^14+44*z^12+20*z^10+9*z^8+4*z^6+2*z^4) = B(z)^4,B(z)])
-- an error. To debug this try: debugmode(true);
Here simpler example :
define(f(z),z^2-1)
(%o3) f(z):=z^2-1
(%i4) f2:factor(f(f(z)))
(%o4) z^2*(z^2-2)
(%i5) e:B(f2) = B(z)^2
(%o5) B(z^2*(z^2-2)) = B(z)^2
(%i6) s:funcsolve(e,B(z))
expt: undefined: 0 to a negative exponent.
#0: rform(%r=[0,0])
#1: funcsol(%a=B(z^2*(z^2-2)) = B(z)^2,%f=B(z),l%=[])
#2: funcsolve(%a=B(z^2*(z^2-2)) = B(z)^2,%f=B(z))
#3: funcsolve(_l=[B(z^2*(z^2-2)) = B(z)^2,B(z)])
-- an error. To debug this try: debugmode(true);
How should I do it?
Is it another software / method for it ?

Any number multiplies by zero equals to zero but why the factorial number of zero equals 1?

Mathematically speaking, zero is the absobing element of the multiplication. I would like to know why the factorial number of zero equals 1? Is this general accepted rule?
Can someone reason about this factorial concept based on this factorial formula?
n!=n×(n−1)×(n−2)×………×1
0! = 0 * 0 = 1
1! = 1 * 1 = 1
2! = 2 * 1 = 2
3! = 3 * 2 * 1 = 6
4! = 4 * 3 * 2 * 1 = 24
5! = 5 * 4 * 3 * 2 * 1 = 120
6! = 6 * 5 * 4 * 3 * 2 * 1 = 720
Here is a description with multiple definitions. 0! is always 1, in mathematics as well as programming. It has to do with data sets.

Good explanation on why x-1 "looks" the way it does in binary

Let's take the number 28 in binary:
0b11100 # 28
If we subtract 1 from the number it looks like this:
0b11011 # 27
How I would explain how it 'looks' is that when subtracting 1 from a number, the right-most 1-bit is set to zero and all zeros after it are set to one. For example:
0b10101 - 1
= 0b10100
0b01000 - 1
= 0b00111
0b10000000 - 1
= 0b01111111
What would be the best explanation as to why this occurs though? I'm sure it's a property of binary twos complement, but I'm trying to figure out the best way to explain this to myself so that I can gain a deeper understanding of it.
Binary numbers have general form of N = dn x b^n + dn-1 x b^n-1… d1 x b^1 + d0 x b^0 where b is a base (2), d is a digit < base (0, 1) and n is position.
We write down binary numbers without b (because we know that's always 2) and also without its n exponent which goes implicitly from 0 for least significant digit (rightmost), 1 next to rightmost, etc.
For example your number 28 is 1x 2^4 + 1x 2^3 + 1x 2^2 + 0x 2^1 + 0x 2^0 = 1x 16 + 1x 8 + 1x 4 + 0x 2 + 0x 1 .
In binary:
1 - 1 = 0
0 - 1 = 1 and you carry that - 1 to the next position on left (same as when you do 10 - 1 in decimal, 0 - 1 is 9 and carry - 1 to order of tenths)
When subtracting 1 you go from the rightmost position, if there's 0 you turn it to 1 and carry subtraction up to next (left) position (and that chains all the way left until you find position where you can subtract without affecting higher position)
0b01000 - 1 can be written as 0x 2^4 + 1x 2^3 + 0x 2^2 + 0x 2^1 + 0x 2^0 - 1 x 2^0. In plain decimal that is 8 - 1 = 7 and 7 in binary is 0x 2^4 + 0x 2^3 + 1x 2^2 + 1x 2^1 + 1x 2^0 (4 + 2 + 1)
It does not matter what base you are in, the math does not change:
1000
- 0001
========
This is base 10, easier to see:
1 0 0 0
- 0 0 0 1
=============
We start in the ones column (base to the power 0), the top number is smaller than the bottom so we have to borrow, but what we find is that next column does not have anything and so on so we have to work over until we can borrow something, that value is base larger than the column it is in so if you borrow from the hundreds column into the tens column that is 10 tens so:
So first borrow:
0 10 0 0
- 0 0 0 1
=============
Second borrow:
0 9 10 0
- 0 0 0 1
=============
Third borrow:
0 9 9 10
- 0 0 0 1
=============
And now we can work the base to the power one column:
0 9 9 10
- 0 0 0 1
=============
9
And in this case can easily finish it up:
0 9 9 10
- 0 0 0 1
=============
0 9 9 9
So base 5:
1 0 0 0
- 0 0 0 1
===================
0 5 0 0
- 0 0 0 1
===================
0 4 5 0
- 0 0 0 1
===================
0 4 4 5
- 0 0 0 1
===================
0 4 4 5
- 0 0 0 1
===================
0 4 4 4
And base 2:
1 0 0 0
- 0 0 0 0
==============
0 10 0 0
- 0 0 0 0
==============
0 1 10 0
- 0 0 0 0
==============
0 1 1 10
- 0 0 0 0
==============
0 1 1 10
- 0 0 0 0
==============
0 1 1 1
Twos complement comes into play when you actually implement this in logic, we know from elementary programming classes that when we talk about "twos complement" we learn to "invert and add one" to negate a number. And we know from grade school math that x - y = x + (-y) so:
0
1000
- 0001
=======
This is the same as:
1 <--- add one
1000
+ 1110 <--- invert
=======
Finish:
10001
1000
+ 1110
=======
0111
So for subtraction you invert/ones complement the second operand and the carry in and feed these to an adder. Some architectures invert the carry out and call it a borrow, some just leave it unmodified. When doing it this way as we see above the carry out is a 1 if there was NO borrow. It is a zero if there was a borrow.
I believe this is a base 2 thing only due to having only zero or one. How do you invert a base 10 number? 1000 - 1 = 1000 + 9998 + 1, hmm actually that works.
So base 10 100 - 1 = 99, base 9 100 - 1 = 88, base 8 (octal) 100 - 1 = 77, base 7 100 - 1 = 66 and so on.

Translation from Binary to Decimal

How does one translate the following binary to Decimal. And yes the decimal points are with the whole binary value
1) 101.011
b) .111
Each 1 corresponds to a power of 2, the power used is based on the placement of the 1:
101.011
= 1*2^2 + 0*2^1 + 1*2^0 + 0*2^-1 + 1*2^-2 + 2*2^-3
= 1*4 + 1*1 + 1/4 + 1/8
= 5.375
.111
= 1*2^-1 + 1*2^-2 + 1*2^-3
= 1/2 + 1/4 + 1/8
= .875
If you don't like dealing with the decimal point you can always left shift by multiplying by a power of 2:
101.011 * 2^3 = 101011
Then convert that to decimal and, since you multiplied by 2^3 = 8, divide the result by 8 to get your answer. 101011 converts to 43 and 43/8 = 5.375.
1) 101.011
= 2*2^-3 + 1*2^-2 + 0*2^-1 + 1*2^0 + 0*2^1 + 1*2^2
= (1/8) + (1/4) + 0 + 1 + 0 + 4
= 5.375
2) .111
= 1*2^-3 + 1*2^-2 + 1*2^-1
= (1/8) + (1/4) + (1/2)
= .875
101.011 should be converted like below
(101) base2 = (2^0 + 2^2) = (1 + 4) = (5) base10
(.011) base2 = 0/2 + 1/4 + 1/8 = 3/8
So in total the decimal conversion would be
5 3/8 = 5.375
Decimal numbers cannot be represented in binary. It has to be whole numbers.
Here is a simple system
Let's take your binary number for example.
101011
Every position represents a power of 2. With the left-most position representing the highest power of 2s. To visualize this, we can do the following.
1 0 1 0 1 1
2 ^ 6 2 ^ 5 2 ^ 4 2 ^ 3 2 ^ 2 2 ^ 1
We go by each position and do this math
1 * (2 ^6 ) + 0 * (2 ^ 5) + 1 * (2 ^ 4) + 0 * (2 ^ 3) + 1 * (2 ^ 2) + 1 * (2 ^ 1)
Doing the math gives us
(1 * 64) + (0 * 32) + (1 * 16) + (0 * 8) + (1 * 4) + (1 * 2) =
64 + 0 + 16 + 0 + 4 + 2 = 86
We get an answer of 86 this way.

How do you convert from IEEE 754 single-precision floating-point format to decimal?

I understand that the first bit is the sign and that the next 8 bits is the exponent. So in this example you would have 1.1001*2^-4 ? How do I then interpret this in decimal?
0 01111011 10010000000000000000000
Since you already figured out that this is (in binary)1.1001*10^-100, now you just have to convert the binary number to decimal.
In decimal, each digit has a value one-tenth as much as the one before it. In binary, each digit has a value one-half as much as the one before it.
First 1.1001*10^-100 = 0.00011001.
Which is...
0 * 1 0 * 1
+ 0 * 1/2 + 0 * 0.5
+ 0 * 1/4 + 0 * 0.25
+ 0 * 1/8 + 0 * 0.125
+ 1 * 1/16 + 1 * 0.0625
+ 1 * 1/32 + 1 * 0.03125
+ 0 * 1/64 + 0 * 0.015625
+ 0 * 1/128 + 0 * 0.0078125
+ 1 * 1/256 + 1 * 0.00390625
0.0625 + 0.03125 + 0.00390625 = 0.09765625
That's all there is to it.
1.1001b is 1*1 + 0.5*1 + 0.25*0 + 0.125*0 + 0.0625*1, or 1.5625. Multiply that by 2**-4 (0.0625) to get 0.09765625.
in C:
int fl = *(int*)&floatVar;