(50g) Decimal IP address to binary octets- HP-50G
|
01-29-2014, 02:59 AM
(This post was last modified: 06-15-2017 01:36 PM by Gene.)
Post: #1
|
|||
|
|||
(50g) Decimal IP address to binary octets- HP-50G
For an IP address such as 172.100.254.4 converts to binary with leading zeros- useful for subnetting.
Place the IP address on the stack: 4: 172 3: 100 2: 254 1: 4 Run the program and the result is: 4: "10101100" 3: "01100100" 2: "11111110" 1: "00000100" << → a b c d @put the contents of the stack in variables a b c d << 97 100 @character codes for the letters: a b c d FOR N a R→B @convert to binary →STR @convert to string ‘a’ STO @store the string in a SIZE 1 – ‘s’ STO @store the size of the string minus 1 in s a 3 s SUB @truncate the extraneous characters ‘a ‘ STO @store this new string in ‘a’ a SIZE 8 @get the size of ‘a’ and put 8 on the stack FOR I “0” a + ‘a’ STO @FOR loop will add the number of missing zeros to make @this an octet NEXT a TAIL @truncate the remaining extraneous characters 1 N + CHR OBJ→ @add 1 to the counter value and convert to the next variable (b ,c or d) ‘a’ STO NEXT @store this in ‘a’ and repeat >> >> |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(50g) Decimal IP address to binary octets- HP-50G - Dwight Sturrock - 01-29-2014 02:59 AM
|
User(s) browsing this thread: 1 Guest(s)