?
Solved

Binary Display Formatter

Posted on 2001-06-21
7
Medium Priority
?
230 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

850 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