-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NARS1] [ksbhaskar] %HD should also work on hexadecimal numbers with a 0x or 0X prefix #45
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
; ; | ||
; Copyright 1987,2001 Sanchez Computer Associates, Inc. ; | ||
; Copyright 1987,2001 Sanchez Computer Associates, Inc. ; | ||
; ; | ||
; Copyright (c) 2017 YottaDB LLC. and/or its subsidiaries. ; | ||
; All rights reserved. ; | ||
; ; | ||
; This source code contains the intellectual property ; | ||
; of its copyright holder(s), and is made available ; | ||
|
@@ -11,15 +14,16 @@ | |
%HD ;GT.M %HD utility - hexadecimal to decimal conversion program | ||
;invoke at INT with %HD in hexadecimal to return %HD in decimal | ||
;invoke at FUNC as an extrinsic function | ||
;Note: Ignores any prefix of 0x or 0X | ||
;if you make heavy use of this routine, consider $ZCALL | ||
; | ||
s %HD=$$FUNC(%HD) | ||
q | ||
INT r !,"Hexidecimal: ",%HD s %HD=$$FUNC(%HD) | ||
q | ||
FUNC(h) | ||
q:$tr(h,"E","e")<0 "" | ||
n c,d,dg | ||
s d=0,h=$tr(h,"abcdef","ABCDEF") | ||
f c=1:1:$l(h) s dg=$f("0123456789ABCDEF",$e(h,c)) q:'dg s d=(d*16)+(dg-2) | ||
n c,d,dg,l | ||
s d=0,h=$tr(h,"abcdefx","ABCDEFX"),l=$l(h) | ||
s:("0X"=$e(h,1,2)) h=($zextract(h,3,l)),l=l-2 | ||
f c=1:1:l s dg=$f("0123456789ABCDEF",$e(h,c)) q:'dg s d=(d*16)+(dg-2) | ||
q d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be the most efficient implementation of FUNC(h), making use of compile time evaluation of operations on constants:
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a matter of esthetics, but the semi-colon box doesn't line up, at least on the Github review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is likely because I have replaced the end of the line with tabs (instead of spaces) and that is how all lines in the rest of the copyright notice are. I do see all lines aligned in the actual code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK