User Tools

Site Tools


cdc:nos2.source:nam5871:ns_cvd

NS$CVD

Table Of Contents

  • [00003] PROC NS$CVD(INW,OUTW1,OUTW2,ERR)
  • [00004] NS$CVD - CONVERT DECIMAL TO BINARY.
  • [00008] CONVERT DECIMAL TO BINARY.

Source Code

NS$CVD.txt
  1. *DECK NS$CVD
  2. USETEXT CYB$NS
  3. PROC NS$CVD(INW,OUTW1,OUTW2,ERR); # CONVERT DEC TO BINA #
  4. # TITLE NS$CVD - CONVERT DECIMAL TO BINARY. #
  5.  
  6. BEGIN # NS$CVD #
  7. #
  8. ** NS$CVD - CONVERT DECIMAL TO BINARY.
  9. *
  10. * J.C. LEE 1981
  11. *
  12. * THIS IS A UTILITY ROUTINE. ITS FUNCTION IS TO CONVERT DECIMAL
  13. * TO BINARY.
  14. *
  15. * PROC NS$CVD(INW, OUTW1, OUTW2, ERR)
  16. *
  17. * ENTRY:
  18. * INW = INPUT WORD, LEFT-JUSTIFIED.
  19. *
  20. * EXIT:
  21. * OUTW1 = OUTPUT BINARY VALUE.
  22. * OUTW2 = OUTPUT RIGHT-JUSTIFIED DC.
  23. * ERR = TRUE/FALSE. (TRUE IF ERROR FLAGED)
  24. *
  25. * METHOD:
  26. * PROCESS A DISPLAY-CODED CHARACTER AT A TIME, UNTIL THE
  27. * WHOLE INPUT WORD IS PROCESSED. FLAG ERROR IF ONE IS FOUND.
  28. *
  29. #
  30. DEF DC$0 #O"33"#; # DISPLAY-CODED 0 #
  31. DEF DC$9 #O"44"#; # DISPLAY-CODED 9 #
  32.  
  33. ITEM INW U; # INPUT WORD, LEFT-JUSTIFIED #
  34. ITEM OUTW1 I; # OUTPUT BINARY VALUE #
  35. ITEM OUTW2 I; # OUTPUT RIGHT-JUSTIFIED DC #
  36. ITEM ERR B; # ERROR INDICATOR #
  37. ITEM COMPLETE B; # CONVERSION DONE INDICATOR #
  38. ITEM DIGIT I; # ONE DISPLAY-CODED CHARACTER #
  39. ITEM I I; # TEMPORARY VARIABLE #
  40. CONTROL EJECT;
  41. ERR = FALSE;
  42. OUTW1 = 0;
  43. OUTW2 = 0;
  44. COMPLETE = FALSE; # CONVERSION NOT DONE YET #
  45.  
  46. FOR I=0 STEP 1 WHILE I LS WC
  47. AND NOT COMPLETE
  48. DO
  49. BEGIN # PROCESS A DISPLAY-CODED CHAR #
  50. DIGIT = C<I,1>INW;
  51.  
  52. IF DIGIT GQ DC$0
  53. AND DIGIT LQ DC$9
  54. THEN # DIGIT IS BETWEEN 0 AND 9 #
  55. DIGIT = DIGIT - O"33";
  56.  
  57. ELSE # NOT A DECIMAL NUMBER #
  58. BEGIN
  59. COMPLETE = TRUE;
  60. IF DIGIT NQ 0
  61. THEN # ERROR IF NOT END OF FIELD #
  62. ERR = TRUE;
  63. END
  64.  
  65. IF NOT COMPLETE
  66. THEN
  67. BEGIN
  68. OUTW2 = OUTW2*O"100" + DIGIT ; # DECIMAL VALUE IN CHAR #
  69. OUTW1 = OUTW1*10 + DIGIT; # CONVERT TO BINARY VALUE #
  70. END
  71. END
  72. RETURN;
  73. END
  74. TERM
cdc/nos2.source/nam5871/ns_cvd.txt ยท Last modified: 2023/08/05 17:22 by Site Administrator