Forum > Spanish
Como convertir valor hexadecimal a su valor ascii
crisares:
Hola a todos
Quisiera saber si alguno me puede ayudar con esto que intento hacer.
A continuacion les muestro como obtengo el valor de la posicion 26 del buffer que es 39h y la muestro en txtChasis... lo que quiero hacer es mostrar el valor ascii correspondiente a 39h que es 9 en lugar del valor hexadecimal.
En realidad necesito mostrar los 17 bytes selecionados en la foto pero en su valor ascii
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- Varch1,v:byte;ch1f:string; Begin MPHex.ReadBuffer(ch1, 26, SizeOf(v)); ch1f := format('%1:.2x',[26,ch1]); txtChasis.Text:= ch1f;end;
lucamar:
Muy básicamente, sin testar la entrada ni que no haya errores, algo como:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function CharFromHex(const Hexa: String): Char;begin if not Hexa.StartsWith('$') then Hexa := '$'+Hexa; {No estoy seguro de si esto es necesario} Result := Chr(StrToInt(Hexa));end;
Eso es todo. ;)
crisares:
Gracias por tu respuesta.. pero no logro que me funcione... voy a seguir avanzando (Aprendiendo) en este lenguaje que es nuevo para mi y volvere a resolver esta parte de mi programa mas adelante.
lucamar:
Perdona, hay un pequeño error en la declaración; debería ser:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- function CharFromHex(Hexa: String): Char; begin if not Hexa.StartsWith('$') then Hexa := '$'+Hexa; {No estoy seguro de si esto es necesario} Result := Chr(StrToInt(Hexa)); end;
El parámetro Hexa no pude ser const si queremos que sea modificable dentro de la función. Es lo que pasa cuando no se prueban las cosas :-[
Con esa pequeña modificación funciona como debe, como se ve en la imagen adjunta.
ETA:
Ahora que me fijo, ya estás cogiendo al valor como byte así que todo lo que tienes que hacer para tener el carácter es llamar a Chr(ch1).
Pues sí que ando yo fino :-[
garlar27:
Yo uso esta función que hice hace años. Tal vez se pueda mejorar pero funciona ...
El parámetro de entrada es una cadena hexdecimal y se asume que ESTÁ COMPLETA, QUE NO ESTÁ DESFAZADA, QUE CADA VALOR HEXADECIMAL ESTÁ REPRESENTADO POR 2 BYTES, QUE NO CONTIENE CARACTERES DIFERENTES DE 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D ,E, F.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function HexToStr(H: string): string;var i: Integer;begin Result := ''; if odd(Length(H)) then begin Exit; end; for i := 1 to Length(H) div 2 do begin Result := Result + Chr(Hex2Dec(H[(i * 2) -1] + H[i * 2])); end; {<--- del for i }end; {<--- HexToStr }
Navigation
[0] Message Index
[#] Next page