Jump to content

Wikipedia:Reference desk/Archives/Computing/2006 October 25

From Wikipedia, the free encyclopedia
Computing desk
< October 24 << Sep | October | Nov >> October 26 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


October 25

[edit]

C++ Decimal percision.

[edit]

How do you get an extremely percise number with C++? Like i know you can use: cout.percision(10); for example But what if i wanted 50 places of percision? I tried to put 50 in the () but i only got i think roughly 10 or so spots of percision (even with a long double data type). is there a limit? is it my compiler? or is it just cause the datatype can't hold it? thanks for the input! --Agester 04:34, 25 October 2006 (UTC)[reply]

According to the floating point article, it should have 52 significants. There might be a limitation to cout or setprecision? I'm not sure, since I don't use them any more. Try printf("%52.50f",variable_name); instead and see if that help at all. If not, I'll look some more.
The 52 number is a number of bits, not decimal digits. The arguments to the formatting functions are counts of digits. (The real answer is given below by Kieff.) --Tardis 15:07, 25 October 2006 (UTC)[reply]
From googling some more, I found that a 64 bit long double only has 17 signicant digits, while a 128 bit long double has 31 significant digits.[1] The 128 bit long double is also not compliant with IEEE standards, and not all compilers support it. And it says on another site that a long double has at least a precision and range of 10, which might be what your compiler is limited to.[2] --Wirbelwindヴィルヴェルヴィント (talk) 05:18, 25 October 2006 (UTC)[reply]
Get some arbitrary precision functions, there are a bunch. ☢ Ҡiff 06:08, 25 October 2006 (UTC)[reply]
Also make sure to be a bit more percise precise in your spelling. Especially when programming, such little slips can create hours of ill-directed debugging attempts. DirkvdM 07:01, 25 October 2006 (UTC)[reply]
This is a lot easier and a lot more complicated than I first thought. Windows XP actually has a shutdown command but it will not work under certain circumstnaces. What I'm working on now is to generate a shutdown batch file that I can executre from the program I'm running along with BIOS controlled startup and startup folder program execution. Any ideas are still welcome. Adaptron 00:38, 26 October 2006 (UTC)[reply]

Internet bandwidth priorities

[edit]

Is there any way to tell what parts of your Internet connection are being used for different applications, including how much bandwidth is devoted to various programs? I'm trying to download something but it's going agonisingly slowly and I suspect there is some background software (knowing my luck, something I never use) hogging up all the bandwidth. I'd like to find it and disable it. Battle Ape 05:53, 25 October 2006 (UTC)[reply]

Not to my knowledge, however, filesharing or download programs, as well as autoupdates, tend to take up bandwidth. I recommend simply ctrl-alt-delete, task manager, and kill everything you don't need (with the exception of Windows of course ;) ). You can also stop using any browsers or anything to your knowledge, ctrl-alt-del, hit Networking, and look at bandwidth usage. If it's high, and you're not doing anything, that's what's up. --Wooty  Woot? | contribs 07:12, 25 October 2006 (UTC)[reply]
No, there is no way to do this 'centrally'. Some software (eg file-sharing and P2P) have settings to limit the amount of bandwidth they use. More likely, a slow download doesn't mean a problem at your end but simply a slow/overloaded server. Most home internet connections can download much faster than most servers can send data, especially if many users are downloading from the same server. A tool to monitor how much bandwidth you're using (such as DU Meter (30-day evaluation)) can be very helpful. — QuantumEleven 10:00, 25 October 2006 (UTC)[reply]
It sounds like a software firewall is what you're wanting. My firewall program monitors incoming/outgoing packet for each process that uses network access. Of course this includes local network usage as well as Internet usage. —Mitaphane talk 19:43, 25 October 2006 (UTC)[reply]

Password-controlled"File Hiding"

[edit]

Question, refdesk.

I want to protect a folder on my PC from being played around with. However, if someone goes into the folder, I don't want them to know it's password protected. I want a program, essentially, that shows a "blank" folder, until I enter a password to show all the others (password function is obviously hidden). Anyone know of such a program? --Wooty  Woot? | contribs 07:10, 25 October 2006 (UTC)[reply]

I'm not sure, but I think you can kinda-sorta do that with TrueCrypt. TrueCrypt is a tool for encrypting data in an easy way. It will mount a virtual volume (ie like you had an extra drive) that encrypts everything you put into it. But that's not all; you can also put a hidden volume on that same encrypted drive. That means that you can have a bunch of files on it, and everyone that sees it will think that that's all there is. But it's not! If you fire up TrueCrypt and enter a different password, suddenly the hidden volume will appear with all of the files you had hidden. Get it? So, set TrueCrypt to mount a certain virtual drive at startup. It will appear empty to everyone (it will appear like a normal folder, so anyone can put stuff into it). But enter a certain password, and as if by magic, another drive will appear. I think that is the closest you're going to get without actually programming a tool yourself. Oskar 17:36, 25 October 2006 (UTC)[reply]

Computer Slowing down with CD Drive interface

[edit]

Hello guys...I use P4,2.6GHz,256 MB RAM,inbuilt video card.I'm using XP with Service pack 2.My pc slows down more severely whenever I try to copy a content from CD.My music also slows down when I copy the data from CD.Why is this?...The CPU usage goes almost 100 when burning CDs using Nero 6 or nero 5..At first when I bought my PC it was not so..Now only the problem persists..It would be nice of you guys if you could provide useful suggestion in getting my PC back to normal..Advance thanks

First of all, check if your CD drive is operating in DMA instead of PIO mode. To do this, follow the instructions on this page. If your DVD drive was running in PIO mode, change it to DMA mode (as explained on the page I sent). If it doesn't work, there is a link at the bottom of the thread to a different way to enable DMA.
If DMA isn't your problem, try updating the firmware on your CD drive. Go to the manufacturer's website and snoop around for a firmware upgrade. Make sure you get the right firmware for your drive!
Also, try running Nero CD-DVD speed, which will give you a detailed analysis of how fast your drive is running, how much CPU it's using, which can help you to pinpoint the problem. Also, Nero InfoTool is very good at giving you details on the settings which may be enabled or disabled on your drive. Good luck! — QuantumEleven 09:55, 25 October 2006 (UTC)[reply]
256mb is awful, you should really get at least 512mb. That might be a contributor to the problem.71.217.195.83 17:00, 25 October 2006 (UTC)[reply]

Also, are you due for a disk defrag ? Fragmentation could slow things down, especially if your computer's going to paging space due to low available memory. StuRat 18:52, 25 October 2006 (UTC)[reply]

Dual booting with Kubuntu and Windows XP

[edit]

Hi all. I was looking to install Kubuntu on my computer so I can dual boot, I currently have XP installed. So I used Partition Magic to create a 10 GB FAT32 partition on one of my hard disks to install Kubuntu (it also created the swap partition for me). I also installed Boot Magic.

After creating the partition, I rebooted with the Kubuntu Live CD in and then started installing it. But I didn't know what to do when it came to the step on which hard disk to install on (step 6 of 7 on the installer). On that step, it showed my 3 physical hard disks but none of the partitions (in particular the newly created FAT32 one). So I chose the "Manually edit partitions table" option (option 3), at which stage I could see the partitions but I had no idea how to choose to install it on the new partition, plus I really had no idea about all the mounting business.

Would it be easier for me to just choose the "resize" (option 1) and create a new partition for it there, and delete the partition I made with Partition Magic. The reason I didn't want to do it before was just in case I accidentally format my hard disks (not something I want to do!) or find myself unable to boot into Windows (if that can even happen).

Any help as to how I should go about doing this? Thanks all (sorry about the long post). - Akamad 11:19, 25 October 2006 (UTC)[reply]

You should have never used PM. Hmm, ok for this I'll assume you want a swap partition and a root partition, nothing fancy like separate partitions for /usr and /home... Go back to PM and delete the partitions you made before, but leave that 10GB of empty space there. On the partition stage of the kubuntu install, edit the partition table and add a new 9GB partition at the beginning of the empty space. Make it ext3 mounted at just a forward slash slash ( / ). Then make another partition at the beginning of the empty space. There should be about 1GB of storage left, but not exactly. Type in 100% to use 100% of the remaining space. Make it of type Linux swap (the first one if there are 2 options for swap). It will mount it to /swap, even if it doesn't say that. --frothT C 01:38, 26 October 2006 (UTC)[reply]
Yeah PM screwed things over for me (Boot Magic didn't help), so I'm just going to format my windows hard disk. That way I figure I'll be able to create clean partitions from the start. All my data and stuff are on other hard disks so ther won't be any data loss. Thanks for your help anyway. - Akamad 09:32, 26 October 2006 (UTC)[reply]
While we're on the topic, is Ubuntu's partitioning procedure capable of resizing existing partitions? It's basically the only reason people started using PM in the first place.  freshofftheufoΓΛĿЌ  09:38, 26 October 2006 (UTC)[reply]
The main distribution method is a livecd, so you could run parted before starting the install procedure. IIRC parted can resize NTFS --frothT C 17:12, 26 October 2006 (UTC)[reply]

What are the highest trafficked Usenet groups?

  • most viewed?
  • most posted to?
  • most replied to?
alt.drugs
(anonymous in case the police is looking for me)

Transfer speed

[edit]

I'm not sure whether to ask this here or at the mathematics reference desk, but it is a computer question so here goes: if I want to transfer a 10 GiB sized file to another person at a speed of 0.5 megabit / second, how long will it take (note that it's megabit/second, not megabyte/second)? I got some different answers when trying to figure it out by myself, but I think the answer is about 1.89 days. Is my calculation correct? 83.250.208.83 12:19, 25 October 2006 (UTC)[reply]

That sounds roughly correct, but there are a lot of other variables ... what is the transfer protocol? What size is each packet? How much header information is required for each packet? and so on ... --LarryMac 12:39, 25 October 2006 (UTC)[reply]
Using my own experience with a 512kbit upload, I know you get about 50-55 KB/s as a transfer rate (assuming nothing else is hogging the upload, of course). Using that speed as a benchmark it should take between 2.2 and 2.43 days. --Pidgeot (t) (c) (e) 15:48, 25 October 2006 (UTC)[reply]

I get 8 bits/Byte x 10 GByte x 1000M/G = = 80,000 Mbits.

Then I get 80,000 Mbits / (0.5 Mbits/sec) = 160,000 secs.

Then I get 160,000 secs x (1 hr/3600 secs) = 44.444 hrs.

Finally I get (44.444 hrs) / (24 hrs/day) = 1.85 days.

Note that this is the minimum time, assuming 100% of the transfer rate is available to this process for the entire time, which is a dubious assumption. StuRat 18:43, 25 October 2006 (UTC)[reply]

Latex Book Margins

[edit]

Hello,

I'm using LaTeX to format a book and this is the first line: \documentclass[a4paper,12pt,titlepage,twoside]{book}

The problem is that the wider margins for binding with my twoside command are on the right side, not the left. How do I get them to reverse?

Thank you for any help,


--CGP 12:41, 25 October 2006 (UTC)[reply]

The twoside option should make the margins alternate between right and left, so they're always on the outside. If you want the chapters to start on left pages rather than right ones, use the option openleft. —Keenan Pepper 18:46, 25 October 2006 (UTC)[reply]
I tried using openleft and openright and they make no difference on my document. Oddly it also does not change anything if I use oneside or twoside. Is there some other option in {book} that I am not aware of? --CGP 19:49, 25 October 2006 (UTC)[reply]
I think the wider margin on the outside of the page is actually for "margin notes". If you include the command
\layout
in your document then LaTeX will put in two pages of diagrams with the margins shown. You can then adjust the values it gives, such as \oddsidemargin and \evensidemargin with commands like
\setlength{\evensidemargin}{17pt}
\setlength{\oddsidemargin}{62pt}
which I think are vaguely sensible numbers to give you a narrow margin on the outside and a largeish binding margin but you'll probably need to fiddle with it somewhat. Bdgoddard 20:45, 25 October 2006 (UTC)[reply]


Hey thanks, it was the margin notes that were throwing off the look. Your new layout commands look perfect. Thanks for the help. --CGP 08:07, 27 October 2006 (UTC)[reply]

Is there a Java keyword for the outer class instance of an inner instance class?

[edit]

If I have the following,

  public class OuterClass {

    private class InnerClass {

      public void increment() {
        ++someVar;
      }

    }

    private int someVar;
    private InnerClass innerClass;

    public OuterClass() {
      this.innerClass = this.new InnerClass();
    }

    public void someMethod() {
      this.innerClass.increment();
    }

  }

Is there a keyword I can use (sort of like this or super) that will allow me to access the OuterClass instance from within InnerClass? One I can wedge in between the ++ and someVar in the increment() method? Thanks. --Silvaran 16:40, 25 October 2006 (UTC)[reply]

To the best of my knowledge, you cannot access the class that contains the "active class" without a reference. Therefore, you must pass this as a parameter to a constructor declared appropriately. However, since the variable is private, I'm pretty sure you can't actually do it even WITH the reference. You will need to create accessors to do whatever it is you want to do. + == Suse 32 vs 64 Bit ==
If the reason to do things like this is to be able to change the way methods are executed in your OuterClass instances, you might want to consider taking a different approach: Change OuterClass to an interface (or abstract class, or class with "standard" functionality - depending on your needs) and use inheritance to create subclasses you can instantiate and place in a variable with OuterClass as the type. Nested classes are, IMO, not really useful unless you need some task done that doesn't make sense outside the class, and doesn't fit in the actual class. --Pidgeot (t) (c) (e) 17:04, 25 October 2006 (UTC)[reply]
I agree, you should use subclasses (or just separate classes) instead. It's always slightly messy to use an inner class, but it can be very useful (mostly for passing functions as arguments, like for instance passing a comparator to java.util.Arrays.sort()). That said, you don't need a keyword. The code you have will increment the OuterClass instance of someVar just fine from InnerClass. Also, you don't need all of those "this." (in someMethod() and the constructor). If there isn't a variable with the local scope that has that name, you don't need to specify that it belongs to the class. Again, I personally think it's a bad design choice to rely to much on inner classes. Separate classes are just so much cleaner, in my opinion. If you can give more detail on what it is you're trying to do, maybe we can help further :) My two cents, anyway. Cheers! Oskar 17:29, 25 October 2006 (UTC)[reply]
I had a situation where an inner instance class had a parameter named the same as a member of the outer class, a la (within InnerClass)
    public void someMethod( int someVar ) { ... }
Quick solution was to rename the parameter. In other situations, I could prefix the member variable with this., so I thought there might be a similar one for accessing an outer class. I prefer the inner instance classes for small groups of methods that operate exclusively on the outer class. In this case, a static nested class would make the outer class instance variable redundant (why not just use an instance class?), and no other classes in the same package can access it like they could a package private class.
The general pattern for the outer class in my case was some kind of pluggable interface. I had a single outer class, a private interface, 4-5 instance classes that implemented this interface, and a member variable pointing to the interface. So I could change the bulk of the behavior on the fly from within the class, and implementors could be kind of chained together (one implementor could create another and point the outer class to it). --Silvaran 18:34, 25 October 2006 (UTC)[reply]
I believe the construct you want is OuterClass.this.someVar; you qualify the this to indicate which "current object" you're talking about. --Tardis 19:26, 25 October 2006 (UTC)[reply]

Suse 32 vs 64 Bit

[edit]

If a 64-bit processor can run both 32 and 64-bit software, is there any advantage to downloading 64-bit SUSE 10.1 over the 32-bit version? --Username132 (talk) 16:58, 25 October 2006 (UTC)[reply]

I would expect the 64-bit version to run faster. StuRat 18:30, 25 October 2006 (UTC)[reply]
I wouldn't, at least not in most instances. The big thing with 64-bit is pretty obvious--the address space. If you have something (database, video editor, whatever) that needs to access more than 3 gigs of memory (2 gigs in Windows IIRC) at a time, INCLUDING virtual memory (stuff paged to disk that looks like RAM to programs), then the 64-bit is going to be faster. With 32-bit, the OS has to make certain compromises (like relying on [PAE] for up to 64 gigs of RAM, but still only 4 gigs of address space for a given process), which are going to slow things down. All other things equal, 64-bit is going to take a little more (though definitely not twice as much) memory to run programs, as addressing will use 64-bit pointers, but that's likely not a concern. Not everything is 64-bit clean yet though, and there are a lot of commercial/proprietary/closed-source applications out there that won't run natively in 64-bit. I suspect Suse has a 32-bit compatibility layer for 64-bit architectures that will solve some--but not all--of these problems. HTH. --Silvaran 18:45, 25 October 2006 (UTC)[reply]
I thought it was not just a matter of address space but also the size of the registers. And I also thought that you only get the benefit if the hardware and the OS and the application are 64-bit. So only recent (and future!) apps that are 64-bit will benefit from using that version of Suse. Or so I thought. DirkvdM 10:17, 26 October 2006 (UTC)[reply]
If the kernel makes use of the larger register sizes (and if it does a good job of it), you do have a potential speed gain. Operations that originally took 2 registers can now be done with one, so theoretically there's a little less moving about into and from cache --frothT C 17:10, 26 October 2006 (UTC)[reply]

Margin Setting

[edit]

Ho do I set the margins in Microsoft Word so that, when the text is printed out, it mesures 7.20 by 4.20?

You may have to set margins on your printer software to accomplish that. StuRat 18:28, 25 October 2006 (UTC)[reply]
Or you can do it through Word's Page Setup box (File -> Page Setup). On the second tab, set the paper size you'll be using (A4, Letter...). Make a note of the paper size. Then go back to the first tab and set the margins so that the printable area is the size you want (you do this by taking, for instance, the height of the paper and subtracting the bottom and top margins to get the vertical size of the printable area). Hope that helps! — QuantumEleven 08:55, 26 October 2006 (UTC)[reply]
There are two other options. You can click and drag the margins in Print Layout View (an editing view of the actual document), which has the virtue of enabling you to use the page rulers right on the page. Or, if you just want a block of text 7.2×4.2, make a table cell that size (it's much easier than doing it thru the margin menus) centre it on the page, and type in that. Anchoress 09:08, 26 October 2006 (UTC)[reply]

PHP Login

[edit]

I am learning PHP and I would like to know how to tell if a person is logged in to a website. For example, I can send a cookie, but how reliable is this? How do I know the cookis is real and not a fake. Thanks, 86.41.151.218 22:56, 25 October 2006 (UTC)[reply]

Start a session. The server will send a session ID (in a cookie) to the client. The next transaction (like they move to a different page on the server), the client will send back that session ID to the server, the server will look up the information associated with that SID (like the current logged in user id, from which other information can be accessed) and display the page based on the SID (like printing the user's user id in the corner of the screen, or applying the site theme that the user has selected in their options). There's no way to tell whether the cookie is forged, unless you encode the SID with the user's IP address (though this can somewhat reduce security if a certain user's IP address is known by an attacker and the encoding scheme is known, and you need to sent the connection type to keep-alive so the user's ISP's DHCP service doesn't issue the user a new IP and thus invalidate the SID). --frothT C 01:31, 26 October 2006 (UTC)[reply]
I'm guessing that this is the session_start() blah, blah, blah stuff. How safe is this? How do other websites do this? How does Wikipedia track users, for example? Thanks, 86.41.151.218 01:53, 26 October 2006 (UTC)[reply]
If you don't use sessions you have to put identifying data (like the users id) into the cookie rather than a SID that points to all that identifying data which is securely on the server. If you don't use sessions, users can potentially edit their cookies to change who they're logged in as (they can do this with sessions too but only if they know their target's SID, which is procurable through XSS attacks). This is from the HTTP cookie article: While cookies are supposed to be stored and sent back to the server unchanged, an attacker may modify the value of cookies before sending them back to the server. If, for example, a cookie contains the total value a user has to pay for the items in their shopping basket, changing this value exposes the server to the risk of making the attacker pay less than the supposed price. The process of tampering with the value of cookies is called cookie poisoning, and is sometimes used after cookie theft to make an attack persistent. Most websites, however, only store a session identifier — a randomly generated unique number used to identify the user's session — in the cookie itself, while all the other information is stored on the server. In this case, the problem of cookie poisoning is largely eliminated. Basically all PHP based sites use php sessions, and sessions as a general idea is almost universally used (I can't think of a single case where sessions aren't used but I could be wrong here). Wikipedia does use PHP sessions through the cookie var "enwiki_session". There's also something called "enwiki_key" that could be used for encoding or something I'll have to look at the mediawiki code. --frothT C 05:40, 26 October 2006 (UTC)[reply]