Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become a VB.NET Expert!

Join 416,726 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,930 people online right now.Registration is fast and FREE... Join Now!



Page 1 of 1
  • You cannot start a new topic
  • Reply Reply

convert from decimal to hexadecimal Rate Topic: -----

#1 maraqa  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-April 08


Dream Kudos: 0

Share |

convert from decimal to hexadecimal

Post icon  Posted 14 July 2008 - 06:21 AM

hi,im not sure this s the best algorithm for conversions (from decimal to hexa) ,and i've done a lot of changes that the code s already a mess.
when run,the program results no output!
any kind of help appreciated :)

	Private Sub BtnHexa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHexa.Click
		Dim c As Integer = 0
		Dim Remainder As Integer
		Dim HexaArray(c) As Integer
		Dim result As Integer

		Dim IntegerDiv As Integer

		Do While Remainder <> 0
			Remainder = IntegerDiv Mod 16
			HexaArray(c) = Remainder
			IntegerDiv = IntegerDiv / 16
			result = result & HexaArray(c)
			c = c + 1
		Loop


		For c = 15 To 0 Step -1
			If HexaArray(c) >= 10 Then
				Select Case HexaArray(c)
					Case HexaArray(c) = 10
						result = "A"
					Case HexaArray(c) = 11
						result = "B"
					Case HexaArray(c) = 12
						result = "C"
					Case HexaArray(c) = 13
						result = "D"
					Case HexaArray(c) = 14
						result = "E"
					Case HexaArray(c) = 15

						result = "F"
						TxtBinary.Text = result



				End Select
			Else
				TxtBinary.Text = TxtBinary.Text & HexaArray(c)
			End If



		Next


	End Sub
	

Was This Post Helpful? 0
  • +
  • -


#2 AmitTheInfinity  Icon User is online

  • C Surfing ∞
  • Icon

Reputation: 82
  • View blog
  • Posts: 1,447
  • Joined: 25-January 07


Dream Kudos: 125

Re: convert from decimal to hexadecimal

Posted 14 July 2008 - 06:24 AM

This may not be the exact solution to your problem [as it is in C] but may help you to build your solution in VB. :)
Was This Post Helpful? 0
  • +
  • -

#3 AndyH1963  Icon User is offline

  • D.I.C Head
  • Icon

Reputation: 22
  • View blog
  • Posts: 201
  • Joined: 22-June 08


Dream Kudos: 0

Re: convert from decimal to hexadecimal

Posted 14 July 2008 - 10:24 AM

Using VB6 to convert from a Hex value to Decimal and vice versa:

   Dim sHexValue As String
   Dim lDecValue as Long

   ' From Hex to Dec:
   lDecValue = CLng("HFFF")
   
   ' From Dec to Hex:
   sHexValue = "&H" & Hex$(4095)



HTH
Was This Post Helpful? 1

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • Icon

Reputation: 1401
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07


Dream Kudos: 12950

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: convert from decimal to hexadecimal

Posted 14 July 2008 - 10:30 AM

Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#5 maraqa  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-April 08


Dream Kudos: 0

Re: convert from decimal to hexadecimal

Posted 14 July 2008 - 07:37 PM

View PostAndyH1963, on 14 Jul, 2008 - 11:24 AM, said:

Using VB6 to convert from a Hex value to Decimal and vice versa:

   Dim sHexValue As String
   Dim lDecValue as Long

   ' From Hex to Dec:
   lDecValue = CLng("HFFF")
   
   ' From Dec to Hex:
   sHexValue = "&H" & Hex$(4095)



HTH


thanks ,but that s not the case,cant u figure out anything wrong with my code that enables it to work?
Was This Post Helpful? 0
  • +
  • -

#6 AndyH1963  Icon User is offline

  • D.I.C Head
  • Icon

Reputation: 22
  • View blog
  • Posts: 201
  • Joined: 22-June 08


Dream Kudos: 0

Re: convert from decimal to hexadecimal

Posted 15 July 2008 - 07:38 AM

View Postmaraqa, on 15 Jul, 2008 - 03:37 AM, said:

View PostAndyH1963, on 14 Jul, 2008 - 11:24 AM, said:

Using VB6 to convert from a Hex value to Decimal and vice versa:

   Dim sHexValue As String
   Dim lDecValue as Long

   ' From Hex to Dec:
   lDecValue = CLng("HFFF")
   
   ' From Dec to Hex:
   sHexValue = "&H" & Hex$(4095)



HTH


thanks ,but that s not the case,cant u figure out anything wrong with my code that enables it to work?



I thought you wanted code to convert from Hex to Dec and vice versa, so that is what I have provided. Why write a load of code to accomplish somthing that is already provided for you? Anyway, you work out where your code is going wrong.
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • The Bandido Coder
  • Icon

Reputation: 359
  • View blog
  • Posts: 4,342
  • Joined: 29-May 08


Dream Kudos: 4650

Expert In: vb.net, LINQ

Re: convert from decimal to hexadecimal

Posted 15 July 2008 - 05:09 PM

Your original code need a few tweaks
	Private Sub BtnHexa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHexa.Click
		Dim c As Integer = 0
		Dim Remainder As Integer
		Dim HexaArray() As Integer
		Dim result As Integer

		Dim IntegerDiv As Integer '<- Need A value

		Do While Remainder <> 0
			Remainder = IntegerDiv Mod 16
Array.Resize(HexaArray,c+1)
			HexaArray(c) = Remainder
			IntegerDiv = IntegerDiv / 16
			result = result & HexaArray(c)
			c = c + 1   
 	Loop
		For c = 15 To 0 Step -1
			If HexaArray(c) >= 10 Then
				Select Case HexaArray(c)
					Case HexaArray(c) = 10
						result = "A"
					Case HexaArray(c) = 11
						result = "B"
					Case HexaArray(c) = 12
						result = "C"
					Case HexaArray(c) = 13
						result = "D"
					Case HexaArray(c) = 14
						result = "E"
					Case HexaArray(c) = 15

					result = "F"


				End Select
				TxtBinary.Text = TxtBinary.Text &  result
			Else
				TxtBinary.Text = TxtBinary.Text & HexaArray(c)
			End If
	Next
	End Sub
	


I think the result maybe back-to-front?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users