Solved

Binary Display Formatter

Posted on 2001-06-21
7
207 Views
Last Modified: 2010-03-31
I would like to be able to display a binary string in the following format:

8 bits:

0000 0000

16 bits

0000 0000 0000 0000

32 bits

0000 0000 0000 0000 0000 0000 0000 0000

Yet when I grab the string, i want to eliminate the space.

Can I perform this task without haveing to tokenize the string to read it every time i want the data.

It there away to build a display formatter...but for the display only..not having to manupulate my original string??

Thanks
0
Comment
Question by:Vernstump
7 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 6217198
public class BinaryDisplay {
  public static void disply(String binary) {
    int l = binary.length();
    if((l % 8 != 0) && (l % 16 != 0) && (l % 32 != 0)) {
      System.out.println("Incorect format.");
      return;
    }
    System.out.print("Binary : ");
    while(binary.length() != 0) {
      System.out.print(binary.substring(0, 4) + " ");
      binary = binary.substring(4);
    }
    System.out.println("");
  }
  public static void main(String[] args) {
    BinaryDisplay.disply("11110000");
    BinaryDisplay.disply("1111000011110000");
    BinaryDisplay.disply("11110000111100001111000011110000");
  }
}
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6217230
public class BinaryDisplay {
  public static void disply(String binary) {
    int l = binary.length();
    if((l % 8 != 0) && (l % 16 != 0) && (l % 32 != 0)) {
      System.out.println("Incorect format.");
      return;
    }
    System.out.print("Binary : ");
    while(binary.length() != 0) {
      System.out.print(binary.substring(0, 4) + " ");
      binary = binary.substring(4);
    }
    System.out.println("");
  }
  public static void main(String[] args) {
    BinaryDisplay.disply("11110000");
    BinaryDisplay.disply("1111000011110000");
    BinaryDisplay.disply("11110000111100001111000011110000");
  }
}
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6217292
public class BinaryDisplay {
  public static void disply(String binary) {
    int l = binary.length();
    if((l % 8 != 0) && (l % 16 != 0) && (l % 32 != 0)) {
      System.out.println("Incorect format.");
      return;
    }
    System.out.print("Binary : ");
    while(binary.length() != 0) {
      System.out.print(binary.substring(0, 4) + " ");
      binary = binary.substring(4);
    }
    System.out.println("");
  }
  public static void main(String[] args) {
    BinaryDisplay.disply("11110000");
    BinaryDisplay.disply("1111000011110000");
    BinaryDisplay.disply("11110000111100001111000011110000");
  }
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:Ovi
ID: 6217310
public class BinaryDisplay {
  public static void disply(String binary) {
    int l = binary.length();
    if((l % 8 != 0) && (l % 16 != 0) && (l % 32 != 0)) {
      System.out.println("Incorect format.");
      return;
    }
    System.out.print("Binary : ");
    while(binary.length() != 0) {
      System.out.print(binary.substring(0, 4) + " ");
      binary = binary.substring(4);
    }
    System.out.println("");
  }
  public static void main(String[] args) {
    BinaryDisplay.disply("11110000");
    BinaryDisplay.disply("1111000011110000");
    BinaryDisplay.disply("11110000111100001111000011110000");
  }
}
0
 

Author Comment

by:Vernstump
ID: 6229827
I dont want to alter the string itself!!

Example:

1111 1111...shoudl be displayed however when the user trys to edit this field....he.she will not be allowed to edit the space between number groups.

0
 
LVL 5

Expert Comment

by:vemul
ID: 7621035
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7643119
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running Jira on Raspberry PI 2? 3 246
Strange loading of website behaviour 3 31
micro services spring boot application error 3 136
nextBoolean(double p) for Random class 3 35
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now