Solved

Binary Display Formatter

Posted on 2001-06-21
7
206 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 9

Expert Comment

by:Ovi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

771 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

10 Experts available now in Live!

Get 1:1 Help Now