The binary equivalent of the decimal number 104 - binary

Ok,so I know that the binary equivalent of 104 is 1101000.
10=1010
4=0100
so , 104=1101000 (how to get this??how these both mix together and get this binary?)
And from the example here...
the octets from "hellohello" are E8 32 9B FD 46 97 D9 EC 37.
This bit is inserted to the left which yields 1 + 1101000 = 11101000 ("E8").
I still understand this part , but how to convert 11101000 to E8?
I'm so sorry for all these noob questions , I just learn it yesterday , I googled and search for a whole day but still not really understand the concept...
Thank you.

Ok,so I know that the binary equivalent of 104 is 1101000.
10=1010
4=0100
You can't break apart a number like 104 into 10 and 4 when changing bases. You need to look at the number 104 in its entirety. Start with a table of bit positions and their decimal equivalents:
1 1
2 10
4 100
8 1000
16 10000
32 100000
64 1000000
128 10000000
Look up the largest decimal number that is still smaller than your input number: 104 -- it is 64. Write that down:
1000000
Subtract 64 from 104: 104-64=40. Repeat the table lookup with 40 (32 in this case), and write down the corresponding bit pattern below the first one -- aligning the lowest-bit on the furthest right:
1000000
100000
Repeat with 40-32=8:
1000000
100000
1000
Since there's nothing left over after the 8, you're finished here. Sum those three numbers:
1101000
That's the binary representation of 104.
To convert 1101000 into hexadecimal we can use a little trick, very similar to your attempt to use 10 and 4, to build the hex version from the binary version without much work -- look at groups of four bits at a time. This trick works because four bits of base 2 representation completely represent the range of options of base 16 representations:
Bin Dec Hex
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F
The first group of four bits, (insert enough leading 0 to pad it to four
bits) 0110 is 6 decimal, 6 hex; the second group of four bits, 1000 is
8 decimal, 8 hexadecimal, so 0x68 is the hex representation of 104.

I think you are making some confusions:
104 decimal is 1101000 which is not formed by two groups splitting 104 into 10 and 4.
The exception is for hex numbers that can be formed by two groups 4 binary numbers (2^4 = 16).
So 111010000 = E8 translates into 1110 = E and 8 = 10000. 1110 (binary) would be 14 (decimal) and equivalent of E (hex).
Hex numbers go from 0 to 15 (decimal) where:
10 (decimal) = A (hex)
11(decimal) = B(hex)
...
15(decimal) = F(hex)

What you're missing here is the general formula for digital numbers.
104 = 1*10^2 + 0*10^1 + 4*10^0
Similarly,
0100b = 0*2^3 + 1*2^2 + 0*2^1 + 0*0^0
And for a hexidecimal number, the letters A-F stand for the numbers 10-15. So,
E8 = 14*16^1 + 8*16^0
As you go from right to left, each digit represents the coefficient of the next higher power of the base (also called the radix).
In programming, if you have an integer value (in the internal format of the computer, probably binary, but it isn't relevant), you can extract the right most digit with the modulus operation.
x = 104
x % 10 #yields 4, the "ones" place
And then you can get "all but" the rightmost digit with integer division (integer division discards the remainder which we no longer need).
x = x / 10 #yields 10
x % 10 #now yields 0, the "tens" place
x = x / 10 #yields 1
x % 10 #now yields 1, the "hundreds" place
So if you do modulus and integer division in a loop (stopping when x == 0), you can output a number in any base.

This is basic arithmetic. See binary numeral system & radix wikipedia entries.

Related

Binary Numbers what is the solution?

Does anyone know how I can solve this problem? Any help would be great...... I cant seem to get my head around it.
As you know binary digits can only be either 1 or 0.
Say you had a 8 digit Binary number like a byte >>>>>> 0001 1000.
I'm trying to figure out an equation for the number of combinations you could get from an 8 digit binary number.
For example, if you had a two digit binary number, the binary combinations that you could have are:
00
01
10
11
Therefore the total combinations from a 2 digit binary number is 4.
Example 2
If you had a 3 digit number, the combinations would be:
000
001
010
100
101
111
110
011
Therefore the number of binary combinations from a 3 digit number is 8.
Example 3
If it were a 4 digit number, maximum binary combinations that you could have are either
0000
0001
0010
0100
1000
0111
0110
1111
1110
1101
1011
1001 Total maximum combination = 12
I Guess in a nutshell what im asking is .... if i had any number 6,7,15,8 or any number... how could i calculate the total maximum Binary combinations is there an equation to it ... I cant figure it out..ive tried for days now ;(
The number of numbers composed by d digits in base b is
b^d
n - number of digits
b - base
^ - power
b^n
So your base is 2 (binary), and u want to check combinations for 8 digit number
2^8 = 256

resulting sum in binary 16

I have answered the question but i could not understand the part where its says get the resulting sum in 16-bit binary, check your answer by converting the sum into decimal.
1.Add ‘A’ and ‘B’ in binary to get the resulting sum in 16-bit binary, check your answer by converting the sum into decimal.
Decimal number = 58927634
A= 5892 to Binary 1011 1000 0010 0
B= 7634 to Binary 1110 1110 1001 0
a + b = 11010011010110
thanks alot
Regards
Let me explain:
A = 00005892
B = 00007634
in base 10 number system, with 8 decimals to represent it.
and...
A = 0001 0111 0000 0100
B = 0001 1101 1101 0010
in base 2 number system, with 16 bits to represent it.
I hope it makes sense to you now.
And the sum of A and B, in base 2 number system with 16 bits to represent it....
0011 0100 1101 0110
although, we needed just 14 bits....
Your answer is correct, but its width is 14 bits long.

Return Base 9 equivalent formula

I have been tackling an exercise given to us by our instructor which is to return the "base 9" equivalent of an inputted number.
The input number is: 231085 and the
return number is: 382871.
I have no idea how he came up with that so called "base 9" equivalent.
I tried looking for the formula on how to get the base 9 equivalent in the web but they were to difficult for me to understand, plus the fact that I am very weak in Math and Algebra.
I tried using modulo and division to solve it and came up with nothing (of course, my formula was wrong).
I'm really dumbfounded on this problem and I would appreciate it if anyone can enlighten me on the formula to solve it.
Or maybe the answer or the problem itself is all wrong?
Cheers!
The base-9 numbering system is a system that uses nine digits to represent numbers. That is,
231,085 = 2 × 105
+ 3 × 104
+ 1 × 103
+ 0 × 102
+ 8 × 101
+ 5 × 100
in the base-10 system, a.k.a. the decimal numbering system. But in the base-9 system, you write it terms of whole multiples of powers of 9, instead of powers of 10 as shown above:
381,881 = 3 × 95
+ 8 × 94
+ 1 × 93 (Your instructor gave you the wrong number, btw. It's 381,881 not 382,871)
+ 8 × 92
+ 8 × 91
+ 1 × 90
Note that the coefficients of the powers of 10 in the base-10 representation (i.e., the 2, 3, 1, 0, 8, and 5) are always one of the ten decimal digits (zero through nine). Likewise, the coefficients of the powers of 9 in the base-9 representation (the 3, 8, 1, 8, 8, 1) are always one of the nine decimal digits (zero through eight). Anything more and you'd have to carry it over, like you learned in the addition of multi-digit numbers in elementary school.
Now, for the algorithm to convert the base-10 representation to base-9, first take a look at Converting a decimal number into binary which converts from base-10 to base-2. The only difference is that you'd divide by powers of 9, instead of powers of 2 as this question does.
Following the example in the linked question,
[231085] [53938] [1450] [721] [73] [1]
÷59049 ÷6561 ÷729 ÷81 ÷9 ÷1
[3] [8] [1] [8] [8] [1]
If you want to systematically break down a base-10 integer into its digits, you'd follow this pattern:
Divide the number by 10 (the base).
The remainder of the division will be the next least significant digit.
Repeat with the new divided number (i.e. the quotient of the division of step 1) until the quotient reaches 0.
So, for 231,085, the iterations are as follows:
Step: 1 2 3 4 5 6
-------------------------------------------------------------
Number: 231,085 23,108 2,310 231 23 2
÷10 ÷10 ÷10 ÷10 ÷10 ÷10
-------------------------------------------------------------
Quotient: 23,108 2,310 231 23 2 0 <-- Quotient reached 0, so stop
Remainder: 5 8 0 1 3 2
As you can see, the remainder in each step is the next least significant digit in the number 231,085. That means 5 is the least significant digit. Then comes 8, which is really 8 × 10 = 80, and 10 > 1; then 0 × 100, and 100 > 10, etc.
Now if you were to divide by 9 in each step instead of by 10 as above, then the table would look something like
Step: 1 2 3 4 5 6
-------------------------------------------------------------
Number: 231,085 25,676 2,852 316 35 3
÷9 ÷9 ÷9 ÷9 ÷9 ÷9
-------------------------------------------------------------
Quotient: 25,676 2,852 316 35 3 0
Remainder: 1 8 8 1 8 3
And now the remainders are in reverse order of the base-9 representation of the base-10 number 231,085.
This answer doesn't actually give you the code for the base conversion, but the basic logic is outlined above, and the algorithm exists all over the internet (maybe for different bases, but all you need to change is the base in the division).
Your instructor's answer is incorrect.
http://www.wolframalpha.com/input/?i=231085+in+base+9

How Does Modulus Divison Work

I don't really understand how modulus division works.
I was calculating 27 % 16 and wound up with 11 and I don't understand why.
I can't seem to find an explanation in layman's terms online.
Can someone elaborate on a very high level as to what's going on here?
Most explanations miss one important step, let's fill the gap using another example.
Given the following:
Dividend: 16
Divisor: 6
The modulus function looks like this:
16 % 6 = 4
Let's determine why this is.
First, perform integer division, which is similar to normal division, except any fractional number (a.k.a. remainder) is discarded:
16 / 6 = 2
Then, multiply the result of the above division (2) with our divisor (6):
2 * 6 = 12
Finally, subtract the result of the above multiplication (12) from our dividend (16):
16 - 12 = 4
The result of this subtraction, 4, the remainder, is the same result of our modulus above!
The result of a modulo division is the remainder of an integer division of the given numbers.
That means:
27 / 16 = 1, remainder 11
=> 27 mod 16 = 11
Other examples:
30 / 3 = 10, remainder 0
=> 30 mod 3 = 0
35 / 3 = 11, remainder 2
=> 35 mod 3 = 2
The simple formula for calculating modulus is :-
[Dividend-{(Dividend/Divisor)*Divisor}]
So, 27 % 16 :-
27- {(27/16)*16}
27-{1*16}
Answer= 11
Note:
All calculations are with integers. In case of a decimal quotient, the part after the decimal is to be ignored/truncated.
eg: 27/16= 1.6875 is to be taken as just 1 in the above mentioned formula. 0.6875 is ignored.
Compilers of computer languages treat an integer with decimal part the same way (by truncating after the decimal) as well
Maybe the example with an clock could help you understand the modulo.
A familiar use of modular arithmetic is its use in the 12-hour clock, in which the day is divided into two 12 hour periods.
Lets say we have currently this time: 15:00
But you could also say it is 3 pm
This is exactly what modulo does:
15 / 12 = 1, remainder 3
You find this example better explained on wikipedia: Wikipedia Modulo Article
The modulus operator takes a division statement and returns whatever is left over from that calculation, the "remaining" data, so to speak, such as 13 / 5 = 2. Which means, there is 3 left over, or remaining from that calculation. Why? because 2 * 5 = 10. Thus, 13 - 10 = 3.
The modulus operator does all that calculation for you, 13 % 5 = 3.
modulus division is simply this : divide two numbers and return the remainder only
27 / 16 = 1 with 11 left over, therefore 27 % 16 = 11
ditto 43 / 16 = 2 with 11 left over so 43 % 16 = 11 too
Very simple: a % b is defined as the remainder of the division of a by b.
See the wikipedia article for more examples.
I would like to add one more thing:
it's easy to calculate modulo when dividend is greater/larger than divisor
dividend = 5
divisor = 3
5 % 3 = 2
3)5(1
3
-----
2
but what if divisor is smaller than dividend
dividend = 3
divisor = 5
3 % 5 = 3 ?? how
This is because, since 5 cannot divide 3 directly, modulo will be what dividend is
I hope these simple steps will help:
20 % 3 = 2
20 / 3 = 6; do not include the .6667 – just ignore it
3 * 6 = 18
20 - 18 = 2, which is the remainder of the modulo
Easier when your number after the decimal (0.xxx) is short. Then all you need to do is multiply that number with the number after the division.
Ex: 32 % 12 = 8
You do 32/12=2.666666667
Then you throw the 2 away, and focus on the 0.666666667
0.666666667*12=8 <-- That's your answer.
(again, only easy when the number after the decimal is short)
27 % 16 = 11
You can interpret it this way:
16 goes 1 time into 27 before passing it.
16 * 2 = 32.
So you could say that 16 goes one time in 27 with a remainder of 11.
In fact,
16 + 11 = 27
An other exemple:
20 % 3 = 2
Well 3 goes 6 times into 20 before passing it.
3 * 6 = 18
To add-up to 20 we need 2 so the remainder of the modulus expression is 2.
The only important thing to understand is that modulus (denoted here by % like in C) is defined through the Euclidean division.
For any two (d, q) integers the following is always true:
d = ( d / q ) * q + ( d % q )
As you can see the value of d%q depends on the value of d/q. Generally for positive integers d/q is truncated toward zero, for instance 5/2 gives 2, hence:
5 = (5/2)*2 + (5%2) => 5 = 2*2 + (5%2) => 5%2 = 1
However for negative integers the situation is less clear and depends on the language and/or the standard. For instance -5/2 can return -2 (truncated toward zero as before) but can also returns -3 (with another language).
In the first case:
-5 = (-5/2)*2 + (-5%2) => -5 = -2*2 + (-5%2) => -5%2 = -1
but in the second one:
-5 = (-5/2)*2 + (-5%2) => -5 = -3*2 + (-5%2) => -5%2 = +1
As said before, just remember the invariant, which is the Euclidean division.
Further details:
What is the behavior of integer division?
Division and Modulus for Computer Scientists
Modulus division gives you the remainder of a division, rather than the quotient.
It's simple, Modulus operator(%) returns remainder after integer division. Let's take the example of your question. How 27 % 16 = 11? When you simply divide 27 by 16 i.e (27/16) then you get remainder as 11, and that is why your answer is 11.
Lets say you have 17 mod 6.
what total of 6 will get you the closest to 17, it will be 12 because if you go over 12 you will have 18 which is more that the question of 17 mod 6. You will then take 12 and minus from 17 which will give you your answer, in this case 5.
17 mod 6=5
Modulus division is pretty simple. It uses the remainder instead of the quotient.
1.0833... <-- Quotient
__
12|13
12
1 <-- Remainder
1.00 <-- Remainder can be used to find decimal values
.96
.040
.036
.0040 <-- remainder of 4 starts repeating here, so the quotient is 1.083333...
13/12 = 1R1, ergo 13%12 = 1.
It helps to think of modulus as a "cycle".
In other words, for the expression n % 12, the result will always be < 12.
That means the sequence for the set 0..100 for n % 12 is:
{0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,11,0,[...],4}
In that light, the modulus, as well as its uses, becomes much clearer.
Write out a table starting with 0.
{0,1,2,3,4}
Continue the table in rows.
{0,1,2,3,4}
{5,6,7,8,9}
{10,11,12,13,14}
Everything in column one is a multiple of 5. Everything in column 2 is a
multiple of 5 with 1 as a remainder. Now the abstract part: You can write
that (1) as 1/5 or as a decimal expansion. The modulus operator returns only
the column, or in another way of thinking, it returns the remainder on long
division. You are dealing in modulo(5). Different modulus, different table.
Think of a Hash Table.
When we divide two integers we will have an equation that looks like the following:
A/B​​ =Q remainder R
A is the dividend; B is the divisor; Q is the quotient and R is the remainder
Sometimes, we are only interested in what the remainder is when we divide A by B.
For these cases there is an operator called the modulo operator (abbreviated as mod).
Examples
16/5= 3 Remainder 1 i.e 16 Mod 5 is 1.
0/5= 0 Remainder 0 i.e 0 Mod 5 is 0.
-14/5= 3 Remainder 1 i.e. -14 Mod 5 is 1.
See Khan Academy Article for more information.
In Computer science, Hash table uses Mod operator to store the element where A will be the values after hashing, B will be the table size and R is the number of slots or key where element is inserted.
See How does a hash table works for more information
This was the best approach for me for understanding modulus operator. I will just explain to you through examples.
16 % 3
When you division these two number, remainder is the result. This is the way how i do it.
16 % 3 = 3 + 3 = 6; 6 + 3 = 9; 9 + 3 = 12; 12 + 3 = 15
So what is left to 16 is 1
16 % 3 = 1
Here is one more example: 16 % 7 = 7 + 7 = 14 what is left to 16? Is 2 16 % 7 = 2
One more: 24 % 6 = 6 + 6 = 12; 12 + 6 = 18; 18 + 6 = 24. So remainder is zero, 24 % 6 = 0

What is the "biggest" negative number on a 4-bit machine?

Or, what is the range of numbers that can be represented on a 4-bit machine using 2s-complement?
That would be -8 to +7
The range is -8 to 7, or 1000 to 0111. You can see the full range here.
4 bits (using 2's complement) will give you a range from -8 to 7.
This should be straightforward to work out yourself.
Range in twos complement will be:
-1 * 2 ^ (bits - 1)
to
2 ^ (bits - 1) - 1
So for 4 bits:
-1 * 2 ^ (4 - 1) = -1 * 2 ^ 3 = -8
to
2 ^ (4 - 1) - 1 = 2 ^ 3 - 1 = 7
Also, if you are interested and for others maybe browsing this question -
twos complement is used for easy binary arithmetic:
to add - you just add the two numbers without conversion and disregard the overflow:
-6 + 7 = 1
is
1010 = -6
0111 = 7
------
(1)0001 = 1 (ignoring the overflow)
...and more yet - to convert a negative binary number to its opposite positive number:
if the sign bit (highest order bit) is 1, indicating negative... reading from least significant to most significant bit (right to left), preserve every bit up through the first "1", then invert every bit after that.
So, with 8 bit
10011000 .. becomes
01101000 (* -1) = 104 * -1 = -104
and that is why 10000000 is your lowest negative number (or in X bit 1000.all zeroes..000), it translates to unsigned 10000000 * -1 = -128
Maybe a long winded answer but to those without the 1s and 0s background I figure it is useful
Well let's dissect this question.
Firstly, the question should be framed as - "The least*(because it is negative, so biggest is not the right usage)* possible negative number to be stored in 4-bit would be?"
Numbers are of two types -
Signed (holds both + and - numbers )
Unsigned (holds only + numbers)
We will be using binary representation to understand this.
For Unsigned -
4-bit minimum number = 0000 (0)
4-bit maximum number = 1111 (255)
So range would be Range : 0-15
For Signed 4-bits, first bit represent sign(+/-) and rest 3-bits represent number.
4-bit minimum will be a negative number.
So replace the first bit(MSB) with 1 in 0000(least unsigned number), making it 1000.
Calculate decimal equivalent of 1000 = 1*2^3 = 8
So, number would be -8 (- as we have 1 as the first bit in 1000)
4-bit maximum will be a positive number.
So replace the first bit(MSB) with 0 in 1111(largest unsigned number), making it 0111.
Calculate decimal equivalent of 0111 = 1*2^2 + 1*2^1 + 1*2^0 = 7
So, number would be +7 (+ as we have 0 as the first bit in 0111)
Range would be -8 to +7.