How can i add zeros to the leading part in each byte of ip address using python so that each byte will always be in 3 digit format. The input and output should be like 1.2.3.4     ==&gt;&gt; 001.002.003.004 1.192.122.5 ==&gt;&gt; 001.192.122.005 192.168.1.1 ==&gt;&gt; 192.168.001.001
1551
What is a Pythonic way to pad a numeric string with zeroes to the left, i.e. so the numeric string has a specific length?
33452
In a shell script, I'm processing, some addition process will print an output. If it is a single-digit one, then it has to add zero as a prefix. Here is my current script: c_year=2020 for i in {01..11}         do               n_year=2020             echo 'Next Year:'$n_year             if [[ $i == 11 ]]             then n_month=12             echo 'Next Month:'$n_month             else              n_month=$(($i + 1))             echo 'Next Month:'$n_month             fi             echo $date&quot; : Processing data '$c_year-$i-01 00:00:00' and '$n_year-$n_month-01 00:00:00'&quot;         done  The i value is in doule digit, but the n_month is still printing single digit. How do I set default shell output should return as double digit? Or any alternate way to solve this?
81981
In python   re.sub(r"(?&lt;=.)(?=(?:...)+$)", ",", stroke )    To split a number by triplets, e.g.:   echo 123456789 | python -c 'import sys;import re; print re.sub(r"(?&lt;=.)(?=(?:...)+$)", ",",  sys.stdin.read());'  123,456,789   How to do the same with bash/awk?
69314
I have several big files with some measurements.   It looks this way:  N 12344;PE 9.9999999;... #S 0 0 31 44 75 130 165 196... #S_+ "2 5 2 3 3 1 1 2 3 1 2 2...  N 12345;PE 9.9999999;... #S 0 0 34 57 84 133 152... #S_+ "1 0 1 1 2 3 0 0 0...  N 12346;PE 9.9999999;... #S 0 0 31 44 73 140 169... #S_+ "3 3 4 0 0 2 1 2 4...  N 25104;PE 9.9999999;... #S 0 0 36 52 102 108 145... #S_+ "1 1 0 1 0 0 3 0 1...  N 25105;PE 9.9999999;... #S 0 0 32 58 88 130 143...   Sample is here:   The file is much bigger but I replaced part of the data with "..." to make it shorter.  I need to somehow replace the line ends before "#S" - in fact simply merge the "N" line with the following two ones into one line (or with the following three ones so I can get rid of the blank lines). Expect output like this:  N 12344;PE 9.9999999; #S 0 0 31 44 75 130 165 196 #S_+ "2 5 2 3 3 1 1 2 3 1 2 2... N 12345;PE 9.9999999; #S 0 0 34 57 84 133 152 #S_+ "1 0 1 1 2 3 0 0 0... N 12346;PE 9.9999999; #S 0 0 31 44 73 140 169 #S_+ "3 3 4 0 0 2 1 2 4... N 25104;PE 9.9999999; #S 0 0 36 52 102 108 145 #S_+ "1 1 0 1 0 0 3 0 1... N 25105;PE 9.9999999; #S 0 0 32 58 88 130 143...   Is this possible to achieve using some command-line utility in linux?   My knowledge is quite limited in this area so I would appreciate any help.  thanks
91461
I found the method .But I do not know how to perform this in VHDL. Let a fixed point number (12 downto -19) like 3456.478396 I need break this number entirely into separate numbers 3456.478396 --> 3,  4, 5,  6,  (dot) ,  4,  7,  8,  3,  9,  6...  into 11 integer type variables. How to perform this in VHDL?  signal example : sfixed(4 downto -4); --'example' contains 9.75 then it is storage as "01001.1100". --simply example ="10011100". --10011100 --&gt; integer 156   How to get back original 9.75 number from 156 to separate into single digits?  I USED,  library ieee; library ieee_proposed; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use ieee_proposed.float_pkg.ALL; use ieee_proposed.fixed_pkg.ALL; use ieee_proposed.fixed_float_types.ALL;
81078
How can I change leading zero in umask 0022? Can it be changed? I searched the usual methods for information and my local system was of little help. $ man umask   No manual entry for umask    $ umask --help bash: umask: --: invalid option umask: usage: umask [-p] [-S] [mode]  I found an  with the following:  umask [-p] [-S] [mode] mode ... File creation mask -S  ........  Print the mask in symbolic format -p  ........  Output in a form that can be reused as input  Based on this, I tried a few basic umask commands: $ umask 0022  $ umask -p umask 0022  $ umask -S u=rwx,g=rx,o=rx  I was surprised to find that I could not run umask with sudo $ sudo umask   [sudo] password :   sudo: umask: command not found    I changed the regular umask as follows: $ umask 021 $ umask 0021  $ umask 0022 $ umask 0022    Finally, I hit an error while trying to change the leading zero $ umask 1022 -sh: umask: 1022: octal number out of range    So, back to my original question, how does one change the leading zero (0)?  Is it for the super user (root)? Can it be updated, and if so, to what? I reviewed a similar question  and found:  I don't know that you would unmask the first bit with umask, but technically you could ...  and  I don't believe you can actually set the umask to allow you to enable any of these extra bits by default  So, these uncertain and contradictory statements do not answer this question.
52574
For no particular reason I stumbled upon the sequence/set of all numbers where all substrings of the decimal representation is prime (A085823). It's quite easy to see that this must be a finite set. My approach was that the digits must alter between 3 and 7 eventually (since a prime can't end with 2 or 5 for larger than that and a prime can't consist of just two non-1 digits, those would be dividable by 2, 5 or 11) and we can see where it ends.  But if we change the base that approach fails. For example in base 8 a prime can end in 3, 5 or 7 AFAICS so such numbers can end in a altering sequence of 3, 5 and 7s but having tree digits to alter between there's always a way to vary the sequence.  I tried to write a python snippet to produce such numbers in different bases and for those I've tested the program seem to hang (ie don't seem to find any more numbers). Is it true that there are only a finite number of such numbers for every base?
58997
I have a public ip as below which is static (my isp provided) as below:  IP Address: x.x.146.50 Subnet Mask:    255.255.255.240 Default Gateway:    x.x.146.49 DNS1:   x.x.1.196 DNS2:   x.x.7.196   But what is my Network, Broadcast and DNS (this scared me for ages, looking for a easy way to do 100% accurate calculating/math).  iface eth0 inet static     address x.x.146.50     netmask 255.255.255.240     network ????????????     gateway x.x.146.49     broadcast ?????????   Follow up: (short cut)  $ ipcalculator 8.8.8.8/28 Address:   8.8.8.8              00001000.00001000.00001000.0000 1000 Netmask:   255.255.255.240 = 28 11111111.11111111.11111111.1111 0000 Wildcard:  0.0.0.15             00000000.00000000.00000000.0000 1111 =&gt; Network:   8.8.8.0/28           00001000.00001000.00001000.0000 0000 HostMin:   8.8.8.1              00001000.00001000.00001000.0000 0001 HostMax:   8.8.8.14             00001000.00001000.00001000.0000 1110 Broadcast: 8.8.8.15             00001000.00001000.00001000.0000 1111 Hosts/Net: 14                    Class A  1) It tells me Broadcast what to copy and paste 2) It tells me Netmask what to copy and paste 3) It tells me Network what to copy and paste   Now its Easy! i was always finding them complex in my head to do manual calculation and server is down for 20 days :P. Not not anymore.
122863
I have a string, lets say "123|ABC|test|12345|FF" and I want to xor the ascii value of each character and print the result in hex.  What is the simplest way?
61612
I'm looking for a  way to convert numbers to string format, dropping any redundant '.0'   The input data is a mix of floats and strings. Desired output:  0   --> '0'  0.0 --> '0'  0.1 --> '0.1'  1.0 --> '1'  I've come up with the following generator expression, but I wonder if there's a faster way:  (str(i).rstrip('.0') if i else '0' for i in lst)   The truth check is there to prevent 0 from becoming an empty string.  EDIT: The more or less acceptable solution I have for now is this:  ('%d'%i if i == int(i) else '%s'%i for i in lst)   It just seems strange that there is no elegant way to handle this (fairly straightforward) case in python.
119051
Why is IP Address listed with this notation 172.18.0.150/24? I mean the ip is 172.18.0.150 only why it haves /24?, and then whatever what subnet that is on should be someone else's worries, no?  3: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether f8:b1:56:ba:ae:ee brd ff:ff:ff:ff:ff:ff inet 172.18.0.150/24 brd 172.18.0.255 scope global eth0   If I want to reach 172.18.0.150 on some interface (ethX) on another computer I could add in the routing table of that computer:  ip route add 172.18.0.150/25 dev ethX or ip route add 172.18.0.150/24 dev ethX or ip route add 172.18.0.150/23 dev ethX or ip route add 172.18.0.150/8 dev ethX    right? So what does /24 really have to do with my address on my NIC? It seems it only has to do with routing, no? So why list it in ip addr?  Is 172.18.0.150/24 on the same "net" as 172.18.0.150/8 or are these two completely different IP addresses?
93031
I am trying to write a script where the user can search for a five digit zipcode using an input statement and a search cursor. The zipcodes in the file though are nine characters long (i.e. xxxxx-xxxx) so I'm trying to use the wildcard character after five digits in the where clause  but I can't figure out either where to put it or the syntax I'm supposed to use. Currently I can get the use input zipcode to print out but when I try putting the % wildcard in I get an error. Can anyone help me?  Here is my code so far:  import arcpy   #set workspace work=raw_input("work= ") arcpy.env.workspace=work zip5=input("zip5= ") strZip= str(zip5)  def searchHospitals(work,zip5):     fc= "Hospital.shp"     whereClause= '"ZIPCODE" LIKE'+"'%s'"% strZip     print whereClause
32263
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this?  I've read that in some languages the result can be machine-dependent, but I'm not sure though.
36723
I have a long sequence of hex digits in a string, such as      000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44   only much longer, several kilobytes.  Is there a builtin way to convert this to a bytes object in python 2.6/3?
5691
Is there a better way of getting this result? This function fails if num has more digits than digits, and I feel like it should be in the library somewhere (like Integer.toString(x,"%3d") or something)  static String intToString(int num, int digits) {     StringBuffer s = new StringBuffer(digits);     int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;      for (int i = 0; i &lt; zeroes; i++) {         s.append(0);     }     return s.append(num).toString(); }
87535
Let's say I have an int with the value of 1. How can I convert that int to a zero padded string, such as 00000001?
63306
How can we extract the decimal part of a floating point number and store the decimal part and the integer part into two separate integer variables?