=BASE(DECIMAL(A1,36),16)
Are you looking to convert each letter to its ASCII code where the code values are displayed using Hex digits (if so, what exactly should the output look like)? If not, exactly what Hex value do you want?How do I convert text to hex? A1 has "google.com". I want to convert those text characters to hexadecimal in B1.
I use a Mac, Excel 2011.
Function Str2Asc(ByVal sInp As String) As String
Dim i As Long
For i = 1 To Len(sInp)
Str2Asc = Str2Asc & Right$("0" & Hex$(Asc(Mid$(sInp, i, 1))), 2)
Next i
End Function
Function Asc2Str(ByVal sInp As String) As String
Dim i As Long
For i = 1 To Len(sInp) Step 2
Asc2Str = Asc2Str & Chr$("&H" & Mid$(sInp, i, 2))
Next i
End Function
It is a weekend and I am bored , so I decided to write your two functions as one-liners ...[Table="width:, class:grid"][tr][td]Row\Col[/td][td]A[/td][td]B[/td][/tr][tr][td]1[/td][td]google.com[/td][td][/td][/tr]
[tr][td]2[/td][td]676F6F676C652E636F6D[/td][td]A2: =Str2Asc(A1)[/td][/tr]
[tr][td]3[/td][td]google.com[/td][td]A3: =Asc2Str(A2)[/td][/tr]
[/table]
Code:Function Str2Asc(ByVal sInp As String) As String Dim i As Long For i = 1 To Len(sInp) Str2Asc = Str2Asc & Right$("0" & Hex$(Asc(Mid$(sInp, i, 1))), 2) Next i End Function Function Asc2Str(ByVal sInp As String) As String Dim i As Long For i = 1 To Len(sInp) Step 2 Asc2Str = Asc2Str & Chr$("&H" & Mid$(sInp, i, 2)) Next i End Function
[table="width: 500"]
[tr]
[td]Function Str2Asc(ByVal sInp As String) As String
Str2Asc = Join(Evaluate("TRANSPOSE(IF(LEN(""" & sInp & """),DEC2HEX(CODE(MID(""" & sInp & """,ROW(1:" & Len(sInp) & "),1))),""""))"), "")
End Function
Function Asc2Str(ByVal sInp As String) As String
Asc2Str = Join(Evaluate("TRANSPOSE(IF(LEN(""" & sInp & """),CHAR(HEX2DEC(MID(""" & sInp & """,2*ROW(1:" & Len(sInp) / 2 & ")-1,2))),""""))"), "")
End Function[/td]
[/tr]
[/table]
How do I convert text to hex?
Welcome to the forum.
You can only convert numbers to hex, not text (unless that text would be a representation of a number in some format).
In Excel 2013 you can use the DECIMAL function to convert "googlecom" (without .) to a number (e.g. if you use a numeric format up to 36, so 0-9 A-Z) and the BASE function to convert the outcome to hexadecimal, returning 2ACFBE9E2CB6, but I don't think this does make much sense at all.
Nevertheless, this would be, only in Excel 2013:
Code:=BASE(DECIMAL(A1,36),16)
Range | Formula | Cells | Iterations | TotalCalcs | Time |
That free time will be convenient to have when you run your one-liner versions
Range Formula Cells Iterations TotalCalcs Time[td]Time/Calc[/td][td]RelSpeed[/td]
[tr][td]C2:C1001[/td][td] =Str2Asc(A2)[/td][td]1,000[/td][td]256[/td][td]256,000[/td][td]3.359[/td][td]0.000 013 123[/td][td]9.7[/td][/tr]
[tr][td]F2:F1001[/td][td] =Str2AscRR(A2)[/td][td]1,000[/td][td]16[/td][td]16,000[/td][td]2.039[/td][td]0.000 127 441[/td][td]1.0[/td][/tr]
[tr][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td]Range[/td][td]Formula[/td][td]Cells[/td][td]Iterations[/td][td]TotalCalcs[/td][td]Time[/td][td]Time/Calc[/td][td]RelSpeed[/td][/tr]
[tr][td]D2:D1001[/td][td] =Asc2Str(C2)[/td][td]1,000[/td][td]256[/td][td]256,000[/td][td]3.066[/td][td]0.000 011 978[/td][td]10.5[/td][/tr]
[tr][td]G2:G1001[/td][td] =Asc2StrRR(F2)[/td][td]1,000[/td][td]16[/td][td]16,000[/td][td]2.004[/td][td]0.000 125 244[/td][td]1.0[/td][/tr]