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

 Dec = xeh (Posted on 2017-08-02)
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.)
 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    hex53   35371   1735141   141599481   184998520280   0820258`

DefDbl A-Z
Dim crlf\$

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

 Search: Search body:
Forums (0)