<br><br><div class="gmail_quote">On 24 February 2011 11:50, tee chwee liong <span dir="ltr">&lt;<a href="mailto:tcl76@hotmail.com">tcl76@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">




<div><div class="im">
&gt; int(s,16) for a hex string<br>&gt; <br><br></div>
great but the leading zeroes are being truncated. <br></div></blockquote></div><br>You need to seperate the concept of display/formatting of some thing from the actual thing/value being displayed.  <br><br>Normally when we humans communicate numbers and or work with them, leaading zero&#39;s are not used, so normally most computer systems and languages will not display numbers with leading zeros by default.  It is therefore up to you to *tell* the computer you want leading zeros in order for it to produce them from the actual value being represented.<br>
<br>Furthermore you need to distinguish (as does the computer) between different object types (namely strings and numbers) as they are different animals which are handled differently by the computer.  <br><br>A number, as already mentioned, will be by default not displayed with leading zeros as that&#39;s normally how humans are used to seeing numbers.  <br>
<br>A string however is a data structure that can contain arbitrary characters.  The computer therefore will generally just display a string with whatever is in it (some exceptions apply for escape characters etc depending on context etc. but ignore that for the moment.)  <br>
<br>Now, a string may contain characters that happens to be the character representation of number (with or without leading zeros) but yet to the computer this remains a string and only a string, until you *explicitly* tell it otherwise and explicitly convert it into an actual number object.  After you&#39;ve done this of course, the computer will know that the thing now being dealt with is in fact a number, and will therefore display/format the number as it usually does (e.g. without leading zeros), again, unless you tell it to display/format it otherwise.<br>
<br>So at the risk of belaboring the points: 1) Get a handle on the fact that numbers and strings are different things, and that on the one hand you&#39;re converting between them.  2) Get a handle on the fact that different things can furthermore be displayed/formatted in a variety of different ways, and there may be many ways to display or represent a given thing, which again is up to *you* to control/specify.<br>
<br>Walter<br><br>