1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Utilities to convert textual presentation of memory to bytes.

This commit is contained in:
Mikhail Khodjaiants 2002-10-25 21:57:00 +00:00
parent b8a4d37318
commit 23529181b2
2 changed files with 31 additions and 0 deletions

View file

@ -1,3 +1,6 @@
2002-10-25 Mikhail Khodjaiants
* CDebugUtils.java: Added utilities to convert textual presentation of memory to bytes.
2002-10-25 Mikhail Khodjaiants
* IFormattedMemoryBlock.java: Replaced 'MEMORY_BYTES_PER_ROW_...' constants by 'MEMORY_NUMBER_OF_COLUMNS_...'.

View file

@ -84,6 +84,17 @@ public class CDebugUtils
charFromByte( (byte)(b & 0x0f) ) };
}
public static byte textToByte( char[] text )
{
byte result = 0;
if ( text.length == 2 )
{
byte[] bytes = { charToByte( text[0] ), charToByte( text[1] ) };
result = (byte)((bytes[0] << 4) + bytes[1]);
}
return result;
}
public static char charFromByte( byte value )
{
if ( value >= 0x0 && value <= 0x9 )
@ -93,6 +104,23 @@ public class CDebugUtils
return '0';
}
public static byte charToByte( char ch )
{
if ( Character.isDigit( ch ) )
{
return (byte)(ch - '0');
}
if ( ch >= 'a' && ch <= 'f' )
{
return (byte)(0xa + ch - 'a');
}
if ( ch >= 'A' && ch <= 'F' )
{
return (byte)(0xa + ch - 'A');
}
return 0;
}
public static char bytesToChar( byte[] bytes )
{
try