Pattern Codes, ABCDE Code, Arduino Code

Saturday 18 March 2017

Program to print String as a Hexcode in java


Program to print String as a Hexcode

Output:

Enter the string to print the hexcode
String length BCDEOFGEHB0E8F82
String value 16

0xBC,0xDE,0xOF,0xGE,0xHB,0x0E,0x8F,0x82

Code:-

import java.util.*;
import java.lang.*;

public class hexcode
{
  public static void main(String[] args)
  {
    int i , n,count,val,val1=0;
    System.out.println("Enter the string to print the hexcode");
    String str = "BCDEOFGEHB0E8F82" ;
    char[] str1 = new char[30];
    System.out.println("String value "+str); 
    n = str.length();
    System.out.println("String length "+n);
    if(n%2 == 0)
      {
      for(i=0;i<n;i++)
      {
         count = 0;
         val = val1;
         System.out.print("0x");
         for(i=val;i<val+2;i++)
            {
        count++;
          val1++;
                  if (count<=2)
                  {
                     str1[i] = str.charAt(i);
                  }
              System.out.print(str1[i]);
             }
             if(i<str.length())
            {
                 System.out.print(",");
             }
         }
     }
    else
     {
         System.out.println("please enter the correct even string value");
      }      
   }

}




No comments :

Post a Comment

Rolls Royce

Rolls Royce
Amazing Cars

About Me