Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Utilities to convert textual presentation of memory to bytes

Utilities to convert textual presentation of memory to bytes.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.31
diff -u -r1.31 ChangeLog
--- ChangeLog 25 Oct 2002 17:05:33 -0000 1.31
+++ ChangeLog 25 Oct 2002 21:56:12 -0000
@@ -1,4 +1,7 @@
 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_...'.
 
 2002-10-25 Mikhail Khodjaiants
Index: src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java,v
retrieving revision 1.4
diff -u -r1.4 CDebugUtils.java
--- src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 17 Oct 2002 23:17:01 -0000 1.4
+++ src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 25 Oct 2002 21:56:12 -0000
@@ -84,6 +84,17 @@
          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 @@
   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


Back to the top