Solved

Binary Display Formatter

Posted on 2001-06-21
7
211 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

828 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