Return-Path: X-Original-To: apmail-flex-users-archive@www.apache.org Delivered-To: apmail-flex-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 739CF17364 for ; Mon, 29 Sep 2014 20:24:30 +0000 (UTC) Received: (qmail 20569 invoked by uid 500); 29 Sep 2014 20:24:30 -0000 Delivered-To: apmail-flex-users-archive@flex.apache.org Received: (qmail 20532 invoked by uid 500); 29 Sep 2014 20:24:30 -0000 Mailing-List: contact users-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@flex.apache.org Delivered-To: mailing list users@flex.apache.org Received: (qmail 20519 invoked by uid 99); 29 Sep 2014 20:24:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Sep 2014 20:24:29 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of webdoublefx@hotmail.com designates 157.55.0.222 as permitted sender) Received: from [157.55.0.222] (HELO DUB004-OMC1S23.hotmail.com) (157.55.0.222) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Sep 2014 20:24:23 +0000 Received: from DUB118-W20 ([157.55.0.238]) by DUB004-OMC1S23.hotmail.com with Microsoft SMTPSVC(7.5.7601.22724); Mon, 29 Sep 2014 13:24:01 -0700 X-TMN: [QkNGH60DhvQwKJCk+EmJz4pfxLDJdWBx] X-Originating-Email: [webdoublefx@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="_85378a81-fbdc-4098-8263-c6d474e1897f_" From: =?iso-8859-1?B?RnLpZOlyaWMgVEhPTUFT?= To: "users@flex.apache.org" Subject: RE: Decimal to Hex conversion. Date: Mon, 29 Sep 2014 21:24:01 +0100 Importance: Normal In-Reply-To: <2FA03CB7-197A-4422-BF9B-9CE99E594FB4@gmail.com> References: ,,,,,,, ,<2FA03CB7-197A-4422-BF9B-9CE99E594FB4@gmail.com> MIME-Version: 1.0 X-OriginalArrivalTime: 29 Sep 2014 20:24:01.0501 (UTC) FILETIME=[4E70B8D0:01CFDC23] X-Virus-Checked: Checked by ClamAV on apache.org --_85378a81-fbdc-4098-8263-c6d474e1897f_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Ok=2C I found the problem in mine for big numbers. @harbs=2C your function works for big numbers but not fractional=2C anyway= =2C I didn't optimize mine=2C so=2C I will use its recursive pattern to rec= ode mine=2C thanks. Fr=E9d=E9ric THOMAS > Subject: Re: Decimal to Hex conversion. > From: harbs.lists@gmail.com > Date: Mon=2C 29 Sep 2014 23:15:35 +0300 > To: users@flex.apache.org >=20 > I have TOTALLY not read this thread=2C but does this function do what you= want? >=20 > function toHex(d) { > var r =3D d % 16=3B > var result=3B > if (d-r =3D=3D 0)=20 > result =3D toChar(r)=3B > else=20 > result =3D toHex( (d-r)/16 ) + toChar(r)=3B > return result=3B > } > function toChar(n) { > const alpha =3D "0123456789abcdef"=3B > return alpha.charAt(n)=3B > } >=20 > On Sep 29=2C 2014=2C at 11:03 PM=2C Fr=E9d=E9ric THOMAS wrote: >=20 > > Also=2C it seems to work for fractional small numbers=2C it doesn't on = big one because this function still rely on the toString(radix) method with= on my windows 64 bits return a wrong result=2C should a bug to be filled o= n Adobe or some else first can confirm those results ? > >=20 > > decimal (10) -> dec2hex -> toString(16) -> real > > 14159265359 -> 0x34.34BF53E2D -> 0x4BF53E4F -> 0x34BF53E4F > > 3.14159265359 -> 0x3.243F6A8885D -> 0x3.0 -> 0x3.243F6A8885A308D > >=20 > > In between I'll try to find a way to code the correct function. > >=20 > > Fr=E9d=E9ric THOMAS > >=20 > >> From: webdoublefx@hotmail.com > >> To: users@flex.apache.org > >> Subject: RE: Decimal to Hex conversion. > >> Date: Mon=2C 29 Sep 2014 20:34:51 +0100 > >>=20 > >> Actually I wasn't sure of mathematical correctness of the solution I g= ave above and I end up writing my own function for it=2C so=2C use it inste= ad of the one I gave before: > >>=20 > >> function dec2hex(dec:Number):String { > >> const carryArr:Array =3D []=3B > >> const integerPart:int =3D parseInt(dec.toString(16))=3B > >> const s:String =3D dec.toString()=3B > >> const iterationMax:int =3D s.substr(s.indexOf(".") + 1).length=3B > >> var fractionalPart:Number =3D parseFloat((dec - integerPart).toFixe= d(iterationMax))=3B > >> var product:Number=3B > >>=20 > >> var hex:String =3D "0x" + integerPart.toString()=3B > >>=20 > >> if (iterationMax > 0) { > >> for (var i:uint =3D 0=3B i < iterationMax=3B i++) { > >> product =3D fractionalPart * 16=3B > >> carryArr[carryArr.length] =3D product.toString(16).toUpperC= ase()=3B > >> const carry:uint =3D parseInt(product.toString())=3B > >> fractionalPart =3D parseFloat((product - carry).toFixed(ite= rationMax))=3B > >> if (fractionalPart =3D=3D 0) > >> break=3B > >> } > >> hex +=3D "." + carryArr.join("")=3B > >> } > >>=20 > >> return hex=3B > >> } > >>=20 > >> You could probably optimize it but at least it returns the correct res= ult. > >>=20 > >> Fr=E9d=E9ric THOMAS > >>=20 > >>> From: webdoublefx@hotmail.com > >>> To: users@flex.apache.org > >>> Subject: RE: Decimal to Hex conversion. > >>> Date: Mon=2C 29 Sep 2014 13:24:21 +0100 > >>>=20 > >>> And to be sure the user is allowed to type decimals only=2C I would a= dd on key down listener a check for it like this: > >>>=20 > >>>=20 > >>>=20 > >>> if( isNaN(Number(scaledVal.text)) ){ > >>>=20 > >>> scaledVal.text =3D scaledVal.sub= string(0=2C str.length-1)=3B > >>>=20 > >>> } > >>>=20 > >>> Or use a preventDefault() > >>>=20 > >>> and to optimize a bit=2C on change=2C check the event is of type CHAN= GE before computing. > >>>=20 > >>> HTH=2C > >>> Fr=E9d=E9ric THOMAS > >>>=20 > >>>> From: sathikeshjith@gmail.com > >>>> Date: Mon=2C 29 Sep 2014 17:42:33 +0530 > >>>> Subject: Re: Decimal to Hex conversion. > >>>> To: users@flex.apache.org > >>>>=20 > >>>> Thanks Frederic. It Worked. > >>>>=20 > >>>> -- > >>>> Regards > >>>> Saju Thankathurai=2C > >>>>=20 > >>>>=20 > >>>> On Mon=2C Sep 29=2C 2014 at 5:27 PM=2C Fr=E9d=E9ric THOMAS > >>>> wrote: > >>>>=20 > >>>>>=20 > >>>>> hexVal.text =3D"0x" + scaledVal.text.split(".").map(function (it= em:*=2C > >>>>> index:int=2C array:Array):String { > >>>>> return int(item).toString(16).toUpperCase()=3B > >>>>> }).join(".")=3B > >>>>>=20 > >>>>> Fr=E9d=E9ric THOMAS > >>>>>=20 > >>>>>> From: miguel.cd.ferreira@hotmail.com > >>>>>> To: users@flex.apache.org > >>>>>> Subject: RE: Decimal to Hex conversion. > >>>>>> Date: Mon=2C 29 Sep 2014 12:49:59 +0100 > >>>>>>=20 > >>>>>> so int is the same! > >>>>>> if uint is just half of int... > >>>>>> lets say you should first read the different types but for your tr= y use > >>>>> number > >>>>>>=20 > >>>>>>> From: sathikeshjith@gmail.com > >>>>>>> Date: Mon=2C 29 Sep 2014 17:16:51 +0530 > >>>>>>> Subject: Re: Decimal to Hex conversion. > >>>>>>> To: users@flex.apache.org > >>>>>>>=20 > >>>>>>> Hi=2C > >>>>>>>=20 > >>>>>>> I tried using int=2C it didnt help. Below is the demo code=2C > >>>>>>>=20 > >>>>>>> > >>>>>>> >>>>>>> xmlns:s=3D"library://ns.adobe.com/flex/spark" > >>>>>>> xmlns:mx=3D"library://ns.adobe.com/flex/mx" > >>>>>>> initialize=3D"windowedapplication1_initializeHandler(event)" > > >>>>>>> > >>>>>>> >>>>>>> import mx.events.FlexEvent=3B > >>>>>>> import spark.events.TextOperationEvent=3B > >>>>>>> protected function > >>>>> scaledVal_changeHandler(event:TextOperationEvent):void > >>>>>>> { > >>>>>>> hexVal.text =3D int(scaledVal.text).toString(16).toUpperCase()=3B > >>>>>>> } > >>>>>>> protected function hexVal_changeHandler(event:TextOperationEvent)= :void > >>>>>>> { > >>>>>>> var texts:String =3D "0x"+hexVal.text=3B > >>>>>>> scaledVal.text =3D int(texts).toString(10)=3B > >>>>>>> } > >>>>>>> protected function > >>>>>>> windowedapplication1_initializeHandler(event:FlexEvent):void > >>>>>>> { > >>>>>>> nativeWindow.maximize()=3B > >>>>>>> } > >>>>>>> protected function button1_clickHandler(event:MouseEvent):void > >>>>>>> { > >>>>>>> scaledVal.text =3D ""=3B > >>>>>>> hexVal.text =3D ""=3B > >>>>>>> } > >>>>>>> ]]> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> >>>>>>> text=3D"Demo to convert hexa to scaled value and vice-versa"/> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> >>>>>>> change=3D"scaledVal_changeHandler(event)"/> > >>>>>>> > >>>>>>> > >>>>>>> >>>>> change=3D"hexVal_changeHandler(event)"/> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>>=20 > >>>>>>>=20 > >>>>>>>=20 > >>>>>>> -- > >>>>>>> Regards > >>>>>>>=20 > >>>>>>>=20 > >>>>>>> Saju Thankathurai=2C > >>>>>>>=20 > >>>>>>>=20 > >>>>>>> *"We **cannot do great things on this Earth=2C only small things = with > >>>>> great > >>>>>>> love"* > >>>>>>> *-Mother Teresa (1910-1997)* > >>>>>>>=20 > >>>>>>>=20 > >>>>>>> On Mon=2C Sep 29=2C 2014 at 5:06 PM=2C Evyatar Ben Halevi-Arbib < > >>>>>>> evyatarbh@gmail.com> wrote: > >>>>>>>=20 > >>>>>>>> You convert initially using uint=2C so decimals are omitted. > >>>>>>>>=20 > >>>>>>>> Regards=2C > >>>>>>>> Evyatar > >>>>>>>>=20 > >>>>>>>> On Mon=2C Sep 29=2C 2014 at 2:22 PM=2C Saju Thankathurai < > >>>>>>>> sathikeshjith@gmail.com> > >>>>>>>> wrote: > >>>>>>>>=20 > >>>>>>>>> Hi=2C > >>>>>>>>>=20 > >>>>>>>>> How can we convert a decimal value to Hex value? > >>>>>>>>>=20 > >>>>>>>>> I need to convert *1345.4567 *value to HEX value. I used the be= low > >>>>> code > >>>>>>>> to > >>>>>>>>> convert decimal values to Hex=2C > >>>>>>>>>=20 > >>>>>>>>> hexVal.text =3D uint(scaledVal.text).toString(16).toUpperCase()= =3B > >>>>>>>>>=20 > >>>>>>>>>=20 > >>>>>>>>> Below code to convert from Hex to decimal. > >>>>>>>>> var texts:String =3D "0x"+hexVal.text=3B > >>>>>>>>> scaledVal.text =3D uint(texts).toString(10)=3B > >>>>>>>>>=20 > >>>>>>>>>=20 > >>>>>>>>> The value 1345 is converted to HEX without any issues. But afte= r > >>>>> the > >>>>>>>>> decimal part=2C it is not converting. > >>>>>>>>>=20 > >>>>>>>>> Could some one give inputs on this conversion. > >>>>>>>>>=20 > >>>>>>>>>=20 > >>>>>>>>> -- > >>>>>>>>> Regards > >>>>>>>>> Saju Thankathurai=2C > >>>>>>>>>=20 > >>>>>>>>=20 > >>>>>>=20 > >>>>>=20 > >>>>>=20 > >>> =20 > >> =20 > > =20 >=20 = --_85378a81-fbdc-4098-8263-c6d474e1897f_--