How to accept max 3 digits in (999) from "(999) 999-999-9999" jquery.maskedinput? - maskedinput

I have used following.
$('#abc').mask("(999) 999-999-9999")
Which allow exact 3 digits at (999) but I want to allow 1, 2 or 3 digits length in place of (999).

Related

Base Conversions between 10 and 2

Suppose you have a 20 digit base 10 positive integer, and you want to represent it in base 2. How many bits are necessary? Why?
I tried : log(2)10 * 10 +1 =66.44 + 1 = 67.44
Then I rounded down to 67 as a final answer
The biggest 20-digit number in base 10 is 10^20-1 (or 20 nines). This number is between 2^66 and 2^67. Since 2^66 is 1 followed by 66 zeros in base 2, it is a 67-digit number. 2^67 is the smallest 68-digit number in base 2. Since 10^20-1 is smaller than that, it is only 67 digits long in base 2. Therefore, a 20-digit number in base 10 is at most 67 digits long in base 2.

How Many Values Can Be Represented With n Digits in Hexadecimal Systems?

I have n = 7. How many different values can be represented using 7 digits in In Hexadecimal Systems?
I approached it this way:
I set each bit of the 7 to be equal to 1. Therefore the highest number I get is 111 1111 = 16^0 + 16^1 + 16^2 + 16^3 + 16^4 + 16^5 + 16^6 which is equal to 17895697. I also consider zero being part of the answer, so my range is 0 to 17895697 and therefore, I get 17895698 different values. however, I know that in binary you would do 2^7 = 128. does it apply to hexadecimals as well? If I do it this way I get 16^7 = 268435456 which does not equal to what I got before.
Is any of my answers correct? if not, could someone please explain what it the right way to do this question?
It may be more simple explanation that you would expect, but it does not mean it would not work.
One hexadecimal digit can represent one of 16 values (0x0 to 0xF, or 0 to 15 if you prefer), so 16^7 = 268,435,456 and that's how many different values you can achieve if you use all the bits.
0000 0000 0000 0000 0000 0000 0000 to 1111 1111 1111 1111 1111 1111 1111.
The general formula is the sum of digit * base^place
Consider decimal numbers. What's the largest number you can represent with 3 decimal digits? The largest possible digit is 9. Therefore the max number is:
9*10^2 + 9*10^1 + 9*10^0 = 9*100 + 9*10 + 9*1 = 999
The next largest number would with be 1*10^3 = 1000
Another way to calculate the max of decimal three digits, is to get the smallest number with 4 digits and subtract 1.
The smallest decimal with 4 digits is 1000 or
1*10^3 + 0*10^2 + 0*10^1 + 0*10^0 = 1000
Now subtract 1
1000 - 1 = 999
The possible digits for a hex num are 0..F (values 0..15)
For a 7 digits the places range from 6 down to 0.
The largest possible number is therefore:
15*16^6 + 15*16^5 .... 15*16^0
Or the smallest number in hex with 8 digits is #10000000
1*16^7 + 0*16^6 ... + 0*16^0 = 1*16^7
So the largest possible number with in hex with 7 digits is
1*16^7 -1
16^7 is the correct answer. Why? Because for every character you add there are 16 times the previous possibilities. So for 7 characters it's 16^7.
Consider binary - 2^1, you get 0 and 1, 2 possible values. 2^2, you get 0 through 3 (00,01,10,11), 4 possible values.
Using hex, it's 16^7 possible values, which is 268,435,456 possible values.

Binary digits in decimal

How do you represent (decimal) integer 50 in binary?
How many bits must be "flipped" in order to capitalize a lowercase 'a' that is represented in ASC11?
How do you represent the (decimal) integer 50 in, oh, "hexadecimal," otherwise known as base-16? Recall that decimal is simply base-10, and binary is simply base-2. Infer from those base systems how to represent this one?
Please answer these questions for me.HELP.
To help you some:
Binary is only made up of 1's and 0's.This may help you understand binary conversion
Decimal is 0-9
Hexadecimal is 0-9, then A-F (so A would represent 10, B would be 11, etc up to F which is 15)
Converting from decimal to another base
Here some tips for you regarding conversion to binary:
What is 50 mod 2? What about 25 mod 2 and then 12 mod 2? What are your results if you continue this?
What does any number mod 2 (always) return as result? - 1 or 0
Do you realise any patterns? - You get the reversed binary number as result
Test case 50:
50 mod 2 = 0 - 6th digit
25 mod 2 = 1 - 5th digit
12 mod 2 = 0 - 4th digit
6 mod 2 = 0 - 3rd digit
3 mod 2 = 1 - 2nd digit
1 mod 2 = 1 - 1st digit
The remainders of the divisions concatenated and reverses are: 110010, which is 50 in binary.
Can this be also transformed to further bases? - Yes, as we see with trying to convert 50 to hexadecimal:
50 mod 16 = 2 - 2nd digit
3 mod 16 = 3 - 1st digit
The remainders again concatenated and reversed are 32, which conveniently is 50 in hexadecimal.
In general we can say to convert a number to an arbitrary base you must take the remainder of the number and the base and then divide the number by the base and do the same thing again. In a program this would look something like:
while the number is greater 0 do:
result = (number mod base) + result;
number = number div base;
Converting from any base to decimal
How do you convert a number from an arbitrary base into base 10? First let us do a test case with binary. Lets take the 50 from the previous example: 110010
The method to convert from binary is multiplying every digit with the base to the power of the position of it in the number and adding up the result. The enumeration of the positions begins with 0 at the least significant digit. Our previous number would then look something like this:
1 *2^5 + 1 *2^4 + 0 *2^3 + 0 *2^2 + 1 *2^1 + 0 *2^0
What simplifies to:
32 + 16 + 2 = 50
It also works with any other base, like our 32 from the previous example:
3 *16^1 + 2*16^0 = 48 + 2 = 50
In program this would look something like this:
from end of number to beginning do:
result = result + digit * (base ^ position)

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

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