Forums Register Login

doubt in a program of convert decimal to Hexadecimal-please clarify

+Pie Number of slices to send: Send
Hello,

i am making a program of convert decimal to Hexadecimal. please write what is difference between these programs.




output is: 38



output is: 8


+Pie Number of slices to send: Send
 

please write what is difference between these programs



In the first case, your do-loop terminates prematurely, and you have code following it that fixes it. In the second case, your do-loop terminates prematurely, and you don't have code following it that fixes it.

IMO, neither case is optimal. Maybe it would be better to fix the do-loop.



Henry
+Pie Number of slices to send: Send

Another suggestion, instead of generating the output string backwards -- requiring the for-loop to reverse it back -- maybe it would be better to generate it in a forward direction. Meaning, instead of this...



How about this...



Henry
+Pie Number of slices to send: Send
Dear Sir,

i am asking in first cast output is: 38 and in the second case output is: 8

when i use that code in a loop


why again write thses outside the loop
+Pie Number of slices to send: Send
 

why again write thses outside the loop



As mentioned, the code outside of the loop is needed because your loop terminated prematurely. It does one more iteration of the loop.

My suggestion is to get rid of that code, and fix the do-loop so that it doesn't terminate prematurely.

Henry
+Pie Number of slices to send: Send
Dear Sir,

thank you for your suggestion.
+Pie Number of slices to send: Send
Dear Sir,

Can you give some light on fix the do-loop so that it doesn't terminate prematurely.
+Pie Number of slices to send: Send
 

Babu lal wrote:Dear Sir,

Can you give some light on fix the do-loop so that it doesn't terminate prematurely.



I showed you the fix, in my first response (not tested, of course).

Henry
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Dear Sir,

Now tested.



Thanks a lot.
moose poop looks like football shaped elk poop. About the size of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1989 times.
Similar Threads
help: java program to convert decimal number to hexadecimal number
hexadecimal numbers
missing return statement?
ASCII TO EBCDIC conversion preserving COMP-3
Evaluating Postfix Expression
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:16:48.