All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Dec = xeh (Posted on 2017-08-02) Difficulty: 3 of 5
Find all numbers of two or more digits in decimal, that are reversed when converted to hexadecimal.

These numbers have something in common. Explain why this is.

No Solution Yet Submitted by Jer    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solutions. Don't know the commonality. | Comment 2 of 5 |
What is being asked is equivalent to saying that if one reverses the digits of a decimal number and treats the results as a hex number, is the number so obtained equal to the original number.

The numbers must be limited to 5 digits or less, as the smallest 6-digit hex number, 100000 hex = 16^5 =  1048576, is a 7-digit decimal number.

The program finds these, in addition to decimals with trailing zeros that lead to hex numbers with leading zeros:

dec    hex
53   35
371   173
5141   1415
99481   18499
8520280   0820258


DefDbl A-Z
Dim crlf$


Private Sub Form_Load()
 Form1.Visible = True
 
 
 Text1.Text = ""
 crlf = Chr$(13) + Chr$(10)
 
 For i = 2 To 15
   d = 10 ^ i: x = 16 ^ i
   Text1.Text = Text1.Text & i & Str(d) & Str(x) & crlf
 Next
 
 Text1.Text = Text1.Text & crlf & " done" & crlf
  

For n = 10 To 9999999
  ns$ = LTrim(Str(n))
  If Left(ns, 1) >= Right(ns, 1) Then
    hx = 0
    For digpos = Len(ns) To 1 Step -1
       hx = hx * 16 + Val(Mid(ns, digpos, 1))
    Next
    If n = hx Then
      hxs$=""
      for i=1 to len(ns)
        hxs$=mid(ns,i,1)+hxs
      next
      Text1.Text = Text1.Text & n & "   " & hxs & crlf
    End If
  End If
  DoEvents
Next
 Text1.Text = Text1.Text & crlf & " done" & crlf

End Sub

I would imagine that the 7-digit limit could be waived if allowing for leading zeros on the hexadecimal side resulting from trailing zeros in the decimal number, as in the last number found above.last number found above.

  Posted by Charlie on 2017-08-02 14:16:35
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (5)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information