single algorithm to convert octal to other number systems [closed] - octal

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have come across a pretty neat algorithm to convert a decimal number to other number systems. program asks for two inputs: number to convert and the base. the output is the number in the base required.
I am wondering if there is possible a single algorithm to convert an octal number to the base of choice?

Of course it is possible. Any number in any base can be written in any other base. For example, it is pretty easy to convert base 8 to base 2, just go one by one from the back and write each number in base 2 using length 3 (this works because 8 = 2^3), e.g.
0o1234
1 > 001
2 > 010
3 > 011
4 > 100
0b001010011100
I bet the same algorithm you use to convert from base 10 to other bases can be easily modified to base 8.

Related

Encoding of the Canadian PostBar barcodes

I am working on a software to encode postal addresses using the PostBar barcode symbology in use in Canada.
I can't find the relevant information for these codes. Wikipedia does describe PostBars, but with a caveat saying that the article is about the D12 type, whereas the Canadian Post actually uses the types D52.01/D82.01/S52.40 and S82.39, which are different and undocumented. (I also know the "CANADA POST CORPORATION 4-STATE BAR CODE HANDBOOK" document, which doesn't help.)
I need the specifics of the encoding of the fields (DCI, Postal Code, Address Locator...) and the parameters of Reed-Solomon parity bits.
I am not after an implementation, which I am able to craft myself. Thank you in advance for any tip.
This is the only thing I could find on the subject. It is not much, I'm afraid:
https://en.wikipedia.org/wiki/Canada_Post#Barcodes
Canada Post uses a 13 character barcode for their pre-printed labels. Bar codes consist of two letters, followed by eight sequence digits, and a ninth digit which is the check digit. The last two characters are the letters CA. The check digit seems to ignore the letters and only concern itself with the first 8 numeric digits. The scheme is to multiply each of those 8 digits by a different weighting factor, (8 6 4 2 3 5 9 7). Add up the total of all of these multiplications and divide by 11. The remainder after dividing by 11 gives a number from 0 to 10. Subtracting this from 11 gives a number from 1 to 11. That result is the check digit, except in the two cases where it is 10 or 11. If 10 it is then changed to a 0, and if 11 then it is changed to a 5. The check digit may be used to verify if a barcode scan is correct, or if a manual entry of the barcode is correct.
And as bonus, an explanation of the barcodes, in Dutch:
https://www.postnl.nl/Images/Brochure-KIX-code-van-PostNL_tcm10-10210.pdf
I don't think we ( Canada Post ) use PostBar anymore. Management made adoption too much of a pain for the mailer so it died. I haven't seen one on an envelope in years. Now that OCR tech is so good it wouldn't help that much to include a PostBar anyway.
What they should have done is given away software that printed up the address labels in alpha-numeric order of the postal code and printed a bunch of positional marks on the top fold of the envelope based on that same postal code. That way a postal clerk need not even take the mail out of the box to see where it should be shipped to. LVM's (large volume mailers) would do this for a rebate on their bill.
Ase for smaller businesses or the general public we should have just soled them prepaid envelopes in 2 or 3 standard sizes for a dime less than the cost of a stamp alone. A standard envelop can have a dedicated spot for a machine readable postal code. I would have gone with good old public-domain Braille! printed or in sharpy:-) Oh well I'm rambling now I'll stop.

plotting excel data in matlab [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
Okay, so i have compiled and done the calculations of a given data on excel spreedsheet. Now, because the data is so large, I want to use matlab to plot it. So, i separated each data set from 1-10 and saved them as txt files on a folder. I would like to use a code to assign some of the columns into column 1 and 2 and so on, say from set 2 for instance, and plot them. How should i approach it? I am currently using "importdata" code. How do i select the column i need in particular? Here is a sample of what i have so far:
set2=importdata(file2.txt)
column3=set2(?) (say i need column 3)
column4=set2(?) (say i need column 4)
plot(column3,column4)
I'm not good at matlab. I would like some help. Thanks
set2 data saved as file2
350 1.2 858 0.02 1300
550 1.4 721 0.02 1300
650 1.8 673 0.02 1300
750 2.2 600 0.01 1300
Note that you could just use MATLAB's built-in xlsread() function for reading data, rather than saving to text file and then loading. Extracting the columns would still be the same as the previous poster's answer.
Use
column2 = set2(:,2)
column3 = set2(:,3)
etc

How long would it take my i-7 processor to factorise a 1024 bits number (consisting of just 2 prime factors) [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
We're examining the RSA algorithm and would like to know how much time it would take an intel i-7 core (# 2.50 gHz) to factorise the RSA-public key.
we wrote a piece of java for this, and I don't know how effective it is
public static String factorise(long l)
{
double a = Math.floor(Math.sqrt(l));
while(l/a != Math.round(l/a))
{
a--;
}
return (long)a + ", " + (long)(l/a);
}
With a number around 2^45 it took the PC approximately 33 milliseconds. In theory, how long would it take to factorise a number around 2^1024?
Thanks in advance :)
Your algorithm is O(2^n), where n is the number of bits in the original number l. (that means that a single bit more will double the runtime, because twice as many numbers a must be checked - on average)
If 45 bits took 33 ms, then 1024 bits will take approx. 2^1024 / 2^45 * 33ms = 5.34654 * 10^285 years.
This of course assumes, that the 1024bit code is exactly as efficient as your code for long numbers (64bit?). Which is a bold statement, considering that 10^285 years is more than enough time to switch to the General number field sieve and scratch a few million years of that time...
In 2009 the 768 bit number rsa-768 was cracked using about 1000 cores and 2 years of calculations. Assuming they used the General number field sieve (a very fair assumption) it would take them 7481 years to crack a 1024 bit number using the same hardware.
Or using only your i7 with this algorithm: about 3 million years. Still a long time.... ;)

Efficient Encoding Schemes [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to choose a encoding scheme for data storage. I have very low available memory. which coding should be best to optimally utilize available space.
ANSI, UTF or any other..
Data is the Capital Alphabetics
If you know the frequency distribution of letters, Huffman Coding is a good balance between complexity, speed and efficiency.
If you don't know the distribution of letters or they are random, just store them 5 bits at a time. For example, consider the string "ABCDE". The letter numbers are 0, 1, 2, 3, 4. Converted to binary, this is:
00000 00001 00010 00011 00100
Now you just group every 8 bits into bytes:
00000000 01000100 00110010 0xxxxxxx
You need to store the length too, so that you know that there is no useful data in the last byte's 7 bits.
If code space is of no concern and you just want to pack the strings as well as you can, you could use Huffman coding or Arithmetic coding even with a uniform frequency distribution to pack each character into log2(26) bits on average, which is slightly less than 5 (namely, 4.7 bits).

How to calculate a number like PI over multiple machines? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
In what way would you try to use multiple computers to compute a number like PI, i.e.?
Are there existing algorithms or solutions that make this easy to do?
How do you split up the work and let the results from other machines come into effect?
Here's one simple way:
generate a huge number of random (x,y) points where x and y are between 0 and 1.
for each point, calculate whether its cartesian distance to the origin is <= 1 (that is, whether it lies on or inside the circle)
count the number of point inside the circle versus outside the circle
Pi, then, can be calculated from the ratio of inside to outside points. A very large number of points is necessary for this to approach pi, but if you have many machines, you can have each computer generate as many as you like, then simply return the counts to some leader machine, which would collect all the results and calculate the final ratio.
This method can be used to calculate pi to any precision you want...the more points, the more precision. It's called a 'Monte Carlo' method because it uses randomness. See http://math.fullerton.edu/mathews/n2003/montecarlopimod.html for more information.
An "easy" version would be using the Bailey–Borwein–Plouffe formula, or its faster variant Bellard Formula. It allows calculating individual (binary) digits of π without calculating the previous ones before.
This means that you can distribute your calculation effort on different computers, which do not have to communicate much. For larger digit indices, you still need distribute the calculation even for a single digit (since you are doing some multiplications and divisions of really large integers).
This was used by the PiHex project to calculate some (binary) digits around digit number 5·1012, some around 4·1013 and some around 1015.
On .Net platform, you can try .net remoting