(15C) Decimal IP address to binary octets- HP15C - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (15C) Decimal IP address to binary octets- HP15C (/thread-1280.html) |
(15C) Decimal IP address to binary octets- HP15C - Dwight Sturrock - 05-09-2014 04:34 PM For an IP address such as 102.16.66.254 converts to binary with leading zeros- useful for subnetting. Place the IP address on the stack: 102 ENTER 16 ENTER 66 ENTER 254 fB (run the program) The result is: t: .01100110 z: .00010000 y: .01000010 x: .11111110 Use "roll down" to see the full address. Runs in about 1 second on the LE, about 1 minute on the HP15C Program listing (ignore everything to the right of each of the //): LBL B FIX 8 STO 1 //store base 10 numbers ROLL DN STO 2 ROLL DN STO 3 ROLL DN STO 4 1 // 1.00401 is for loop control . 0 0 4 0 1 STO I LBL 2 RCL (i) //B10 # 8 CHS STO 9 //place value 0 STO 0 //B2 to be built LBL 0 RCL (i) X=0 //if x=0 the number has been converted GTO 1 INT 2 //divide by 2 method of base conversion / STO (i) FRAC ENTER + RCL 9 //place value 10^x * STO +0 //B2# building 1 STO +9 //increment place value GTO 0 LBL 1 RCL 0 //B2 converted STO (i) ISG I // if we have reached 4, all octets are converted GTO 2 RCL 4 RCL 3 RCL 2 RCL 1 RTN |