how to read number and print it out digit by digit - plsqldeveloper

Write a program to read in a number and print it out digit by digit, as a series of words. For example, the number 523 would be printed as "five two three". Use decode function within a for loop. Display the results on the screen using dbms_output.put_line.

Here's a fairly extensive forum thread on this by the popular Tom Kyte:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1407603857650

Related

Binary numbers addition

I have just started doing some binary number exercices to prepare for a class that i will start next month and i got the hang of all the conversion from decimal to binary and viceverca But now with the two letters 'a ' ' b' in this exercise i am not sure how can i apply that knowledge to add the bits with the following exercise
Given two Binary numbers a = (a7a6 ... a0) and b = (b7b6 ... b0).There is a clculator that can add 4-bit binary numbers.How many bits will be used to represent the result of a 4-bit addition? Why?
We would like to use our calculator to calculate a + b. For this we can put as many as eight bits (4 bits of the first and 4 bits of the second number) of our choice in the calculator and continue to use the result bit by bit
How many additions does our calculator have to carry out for the addition of a and b at most? How many bits is the result maximum long?
How many additions does the calculator have to perform at least For the result to be correct for all possible inputs a and b?
The number of bits needed to represent a 4-bit binary addition is 5. This is because there could be a carry-over bit that pushes the result to 5 bits.
For example 1111 + 0010 = 10010.
This can be done the same way as adding decimal numbers. From right to left just add the numbers of the same significance. If the two bits are 1+1, the result is 10 so that place becomes a zero and the 1 carries over to the next pair of bits, just like decimal addition.
With regard to the min/max number of step, these seems more like an algorithm specific question. Look up some different binary addition algorithms, like ripple-carry for instance, and it should give you a better idea of what is meant by the question.

Regular expression for valid US phone number

I'm trying to cleanse a data set from erroneous phone number entries. Having trouble making the regular expression for the filter in MySQL.
The structure is the following:
First digit is in 2-9
Second and third digits can be any numeral except they may not be the same number
Forth digit is in 2-9
Fifth and sixth digits can be any numeral except '11'
I've landed on a few rather elaborate reg expressions which didn't quite work; but I'm sure there is a simplistic approach.
A "valid" number might look like:
2028658680
7137038891
My filter usually misses cases such as:
6778914351
7777777777
6178116678
Note that these numbers are completely made up.
This is possible, but it will be long and ugly. With a more robust regex engine you can do lookaround and even conditional statements, but MySQL doesn't support such things as far as I know.
^[2-9](?:0[1-9]|1[02-9]|2[013-9]|3[0-24-9]|4[0-35-9]|5[0-46-9]|6[0-57-9]|7[0-689]|8[0-79]|9[0-8])[2-9](?:1[02-9]|[02-9]1|[02-9]{2})[0-9]{4}$
https://regex101.com/r/qPuS5W/1
Explanation:
[2-9] First digit is any number from 2 to 9.
(?:0[1-9]|1[02-9]|2[013-9]|3[0-24-9]|4[0-35-9]|5[0-46-9]|6[0-57-9]|7[0-689]|8[0-79]|9[0-8]) Non capturing group that contains 10 alternatives starting with each number 0 to 9 followed by any number except that number.
(?:1[02-9]|[02-9]1|[02-9]{2}) Non capturing group that matches either 1 followed by a number that isn't 1, a number that isn't 1 followed by 1, or two numbers that aren't 1.
[0-9]{4} 4 of any number.

How to identify different patterns of numbers in a column?

I am trying to write one single formula to identify all the patterns in a column/field. For example: Below are the five different patterns
AG 5643 895468 UWEB
7546 695321 IJJK
PE 45612384
8642567921
16724385
Formula for
First pattern: Contains 4 numbers 6 numbers
'*[0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9][0-9][0-9] *' This is not working. Can we specify the length? Something like this [0-9]{4} - 4 digit number?
First pattern should pick second one also.
3rd one: first 2 characters are alphabets 8 or 10 digit numbers
4th one: 10 digit number
5th one 8 digit number
Thanks in advance!
If you're working in MySQL you can use regular expressions with the RLIKE filter operator.
For example, WHERE text RLIKE '[0-9]{8}' finds all the rows with any consecutive sequence of eight digits in them anywhere. (http://sqlfiddle.com/#!9/44996/1/0)
WHERE text RLIKE '^[0-9]{8}%' finds the rows consisting of nothing but an eight-digit sequence. (http://sqlfiddle.com/#!9/44996/2/0)
WHERE text RLIKE '^[0-9A-Z]{2} ' finds the rows starting with two letters or digits and then a space. (http://sqlfiddle.com/#!9/44996/3/0)
You get the idea. Regular expressions have a lot of power to them, generally beyond the scope of a SO answer to explain. Beware, though. This is a common saying: If you solve a problem with e regular expression, now you have two problems. You need to be careful with them.

Binary Calculator using Picaxe microchip?

I want to be a complete nerd and make a very simple binary calculator.
It will be two rows of 8 switches, each switch representing a bit, so a row is a byte (number), the two rows are added together, and a row of 9 LED's will display the result in binary.
Is this possible to do with a picaxe microchip?
If not, what could I do it with?
Cheers,
Nick
Your problem would be data input/output lines. The basic idea is trivial in any microcontroller, but it's the number of input/output pins available.
You might want to look into several shift registers (one per row and one per output) so you can marshal the bits in on a single pin or two and out on a single pin.
Specifically:
74hc165n parallel-in/serial-out for the inputs
74hc595 for the output.

How to used the alphabet binary symbols

I was reading an article on binary numbers and it had some practice problems at the end but it didn't give the solutions to the problems. The last is "How many bits are required to represent the alphabet?". Can tell me the answer to that question and briefly explain why?
Thanks.
You would only need 5 bits because you are counting to 26 (if we take only upper or lowercase letters). 5 bits will count up to 31, so you've actually got more space than you need. You can't use 4 because that only counts to 15.
If you want both upper and lowercase then 6 bits is your answer - 6 bits will happily count to 63, while your double alphabet has (2 * 24 = 48) characters, again leaving plenty of headroom.
It depends on your definition of alphabet. If you want to represent one character from the 26-letter Roman alphabet (A-Z), then you need log2(26) = 4.7 bits. Obviously, in practice, you'll need 5 bits.
However, given an infinite stream of characters, you could theoretically come up with an encoding scheme that got close to 4.7 bits (there just won't be a one-to-one mapping between individual characters and bit vectors any more).
If you're talking about representing actual human language, then you can get away with a far lower number than this (in the region of 1.5 bits/character), due to redundancy. But that's too complicated to get into in a single post here... (Google keywords are "entropy", and "information content").
There are 26 letters in the alphabet so you 2^5 = 32 is the minimum word length than contain all the letters.
How direct does the representation need to be? If you need 1:1 with no translation layer, then 5 bits will do. But if a translation layer is an option, then you can get away with less. Morse code, for example, can do it in 3 bits. :)