Formatting Binary Output
I want to format binary output in text fields to confrom to the following scheme:
head data1 data2 return offSet id
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
where the first row are field names and the second is the filed width.
What that means is that, using the value 1 (base 10) as an example, a 6 bit filed will read 000001 and so a 5 bit field will read 00001.
My program converts to binary no worries, but how do I enforce the width requirements? I am using Integer.toBinaryString(int) to convert, if that helps.
Thanks
public String intToJustifiedBinaryString(int number, int length)
StringBuffer buffer = new StringBuffer(Integer.toBinaryString(number));
while (buffer.length() < length)
buffer.insert(0, "0");
return buffer.toString();It works great! Now for the learning. I looked up StringBuffer and found this explanation:
StringBuffer(String str)
Constructs a string buffer so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string buffer is a copy of the argument string.
What I am trying to figure out is how it is not overwriting what already exists in the buffer. Lets pretend with int = 7 and a 6 bit field.
So initially, buffer.length() = 3 and my buffer looks like 1 1 1.
From the API: The principal operations on a StringBuffer are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string buffer. The append method always adds these characters at the end of the buffer; the insert method adds the characters at a specified point.
If I am specifying my insert point as 0 (insert(int offset, char c) Inserts the string representation of the char argument into this string buffer.) How am I not overwriting one of my bits comprising my binary 7? My only guess is that insert operation first shifts what is already there over the necessary amount, based on the length of what is being inserted, before inserting at the specified point. I have read nothing to support this theory. Please let me know if it is correct.
Thanks for the help!
Similar Messages
-
How to display binary output in numeric indicator
Hai
How to display binary output in a Numeric display.
in my program i use numeric display for displaying numeric values in one case
in the other case i want to display binary output in the same numeric display window as binary,
i don't want to make seperate o/p display for binary o/p i want change the property of the Numeric display to binary display .
is it possible to display Binary data in numeric indicator, please give me an idea to do this.
thanks
sk
Attachments:
DBL2BIN.vi 39 KBAlternatively, you can use the FormatString property node, and use %08b as format string : 08 means : pad the output with 0 to get a 8 digits wide result.
See attachment.
Chilly Charly (aka CC)
E-List Master - Kudos glutton - Press the yellow button on the left...
Attachments:
DBL2BIN[1].vi 21 KB -
In previous OTN Forum format we used {code} to format sqlplus output , how to do in this version ?
Click on "Use Advanced Editor".
Highlight your code.
Click on the symbol >>
Select Syntax Highlighting
Select SQL...output looks like below:
select sysdate from dual; -
Passing binary output in servlets
Hi all,
I am new to struts.In Jsp i need to give three text field values
1.category
2.two date fields.
On click of submit button,it should export the csv file from db into excel sheets.
If i didnt give the input values properly and clicking the submit button will display the error msg.
But next time if i give the proper input values,then it should disappear.
but my problem is the err msg is not removing from jsp but export is working and in my console :
SEVERE: Servlet.service() for servlet action threw exception+
java.lang.IllegalStateException: Cannot forward after response has been committed*
**and in my action class:**
The following condition is to check existence of err:
if (category.length() == 0 || startdate.length() == 0
|| enddate.length() == 0) {
ActionMessages errors = this.getErrors(request);
errors.add("fatal", new ActionMessage(DATE_FIELD_MISSING, ""));
saveErrors(request, errors);
return mapping.findForward("failure");
The following code is for export the data:+
if (category.equals("book")) {
String fileName = "part.csv";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\""
+ fileName + "\"");
try {
OutputStream oStream = response.getOutputStream();
oStream
.write(" Number, Description, Revision, Dummy, Manual, Classification, Owner, Global Effective Date, Global Expiration Date, New Part\n"
.getBytes());
for (int i = 0; i < result.size(); i++) {
PartDTO part = (PartDTO) result.get(i);
StringBuffer sbpart = new StringBuffer(part.getPartNumber());
sbpart.append(',');
sbpart.append(part.getPartDescription());
sbpart.append(',');
sbpart.append(part.getRevision());
sbpart.append(',');
sbpart.append(part.getIsDummy());
sbpart.append(',');
sbpart.append(part.getIsManual());
sbpart.append(',');
sbpart.append(part.getClassification());
sbpart.append(',');
sbpart.append(part.getOwner());
sbpart.append(',');
sbpart.append(part.getEffectiveDate());
sbpart.append(',');
sbpart.append(part.getExpirationDate());
sbpart.append(',');
sbpart.append(part.getIsNewPart());
sbpart.append("\n");
oStream.write(sbpart.toString().getBytes());
oStream.close(); } catch (IOException ioe) {
return mapping.findForward("success");
I think oStream.close() will return to jsp .. so the last return statement is not working..
I dont know how to do it in someother way......Plz help me.its urgent yaar......Thanks in advance....It's been awhile since I've used Struts, so don't put too much stock in this answer. That said...
Generally, you should not close the response output stream, ever. The application server takes care of this, when and if the time is right.
Also, it appears that you're writing output within an action, and then forwarding to a JSP. If you want to write binary output or some other type of output for which a text-template based JSP is not appropriate, forward to a plain old servlet, and write your output there. Define the servlet as you would any other in web.xml, and dispatch to it from Struts instead of going to a JSP.
Good luck!
- Jerry Oberle -
Need Formatted html output from Xalan
We use xalan xslt processor to convert
xml document to html. Everything works
fine, except the output is unformatted html.
(ie. several HTML elements appear on the
same line. Some lines are longer than 1000
characters). This happens inspite of me
specifying the HTML elements in different
lines in the xsl.
I would like to know if there is any way, I can generate formatted html output.
Thankshave u tried
<xsl:output indent="yes"/>
in your stylesheet?
ravi <[email protected]> wrote:
We use xalan xslt processor to convert
xml document to html. Everything works
fine, except the output is unformatted html.
(ie. several HTML elements appear on the
same line. Some lines are longer than 1000
characters). This happens inspite of me
specifying the HTML elements in different
lines in the xsl.
I would like to know if there is any way, I can generate formatted html
output.
Thanks -
Formatting printer output for dotmatrix printer
Hi Experts,
i'm trying to format the output of the EPSON LQ-870 dot matrix printer to print the output in the paper size height 280 mm & width 210 mm.The device type i used for my output device is EPESCP2.For the first page the header and line items are coming correctly.But for the second page onwards, there is some space is coming between each line items.In third page,the header is coming little bit down from the required location.My page size is little bit less than the normal A4 size.How to rectify this?
Points will be rewarded if helpful.......
Thanks in advance.Hello,
I created a condition table '550 - Shipping point/plant'. Then I created an access sequence 'ZSH1' and assigned this condition table 550 to it.
In the output determination procedure, the procedure 'V10000 - Header output' has the condition type PL02 - BOL: Single Delivery assigned to it.
The assignments look like:
Step Counter Cond Type
10 1 LD00 Delivery Note
20 2 PL00 Packing list
30 3 PL01 Planning Slip
40 4 PL02 BOL: Single Delivery
In Assign output procedures, the entry corresponding to delivery type 'LF' is:
Del Type O/P procedure O/P Type
LF Delivery V10000 Header Output LD00Delivery Note
When I try to enter a new condition record using VV21, it does not show up this key combination 'Shipping point/Plant'.
Can someone tell me if I am missing some customization?
Thanks,
Rugmani
Edited by: Rugmani Rajan on Oct 22, 2008 3:06 PM -
Formatting the output (currency with decimals)
hi all,
i want to format the output of the currency field. Right now it displays the exact value like say 23 or 43.5 etc. But my requirement is i need it to display in a standard format as 23.00 , 43.50 , 565.00 etc. i,e if there is no decimals then it should be filled with zero's.
I have gone through some of the threads which speaks of formatting the output if it is a value node. But here i have directly bounded the table to a model node.
Domian level datatype of the field is Currency in R/3. After model import in dictionary it is showing as decimal.
How can i achieve this?I Appreciate if someone can help me on this.
Regards,
G Nidhi,
Go thru this link it might helps you.
column heading -refer to the webdynpro tutorial 34
Change the currency data type char and specify the length.
Thanks,
Lohi. -
Hi everyone in the forum,
I do not know if i should post this question here, but i think is the best place. Sorry if i were wrong.
just a question because i have no idea how to format the output i need.
I have a REAL or FLOAT and the output restrictions shows that it should be:
1.0000 D-08 if the value is less than 1
1.0000 if the value is [1,9]
1.0000 D+03 is value bigger than 9
and the other problem is whith other variable (type String) which represents integers, e.g, 0.000000 1.0000000 2.000000; and i have to return only 0 1 2 .
Any suggestion about how to format the output?
ThanksDecimalFormat
-
Hi: how do I format the output so that it shows me the complete value for the EVENT_ID field
===========
SQL> select /*+ FIRST_ROWS */ EVENT_ID from EVENT_DATA where AGENT_ID IN (160,212,264);
EVENT_ID
4.9561E+18
4.9561E+18
================
TIA
RaviYou can also change numwidth in sql*plus
SQL> select 12345678901234567890 from dual;
12345678901234567890
1.2346E+19
SQL> set numwidth 20
SQL> /
12345678901234567890
12345678901234567890 -
how do i format the output of an array so that only a certain number of the elements print per line. i know this is basic, i am a beginner and need help.
final int itemsPerLine = 5;
int counter = 0;
String myArray[]; // This will contain your array
while (counter < myArray.length) {
System.out.print(myArray[counter]; // Print out the item
counter++; // increment our counter;
if (counter%itemsPerLine == 0) {
System.out.print("\n"); // ad a line return
}This is one example. It prints out the next string in the array (which you need to initialise and populate first), increments the counter, then checks the modulus to see if its time for a newline.
Rob. -
Invalid END header format/no output available for this tool
help me.
I install oracle 9i into windows 2k server with pack3. when configuring the ODCA, when OUI prompt:
invalid END header format&
no output available for this tool.
who can tell me that what is happen?
before this, i had installed this version on windows 2003.Dear All
I have the same problem when installing Oracle9iasR2 on a windows 2000 IBM server
At the database configuration Assistant of the infrastructutre installation I am always getting this strange message Not a ZIP file (End Header Not found).
We have tried a lot off scenarios to install Oracle9iasr2 but the installation always fails at the database creation with the followning message
Not a ZIP file (End Header Not found).
We had also tried to do the installation using a different copy of CD's with no success.
Also the same installation on the same server was succesfull with O/S Win2003.
Then the whole installation fails .
If anyone has ever faced the same problem and had solved it please advice.
Thank you in advance.
Bill -
Help with formatting multiline output into comma delimited ordered output
I have 2 tables:
SQL> desc table_1;
Name Null? Type
===================================
ID NOT NULL NUMBER
DATA1 NOT NULL VARCHAR2(440)
DATA2 NOT NULL VARCHAR2(1024)
SQL> desc table_2;
Name Null? Type
===================================
ID NOT NULL NUMBER
ATTNAME NOT NULL VARCHAR2(255)
ATTVAL VARCHAR2 (4000)
DATA1 NOT NULL CHAR(1)
DATA2 VARCHAR2 (2000)
DATA3 VARCHAR2 (255)
I need to get ATTVAL from where e.g. ATTNAME=att_name1 to ATTNAME=att_name6 from every entry (with its unique ID), and format the output into comma delimited format in e.g. this order:
att_val1,att_val3,att_val6,att_val4,att_val5,att_val6
So e.g. for entry with ID "9812" from the query below, the output I need would be:
187,179,156,134,1436,1809
What I've got so far is as follows:
SQL> SELECT id,attname,attval FROM table_2 WHERE id in (SELECT id from table_1 WHERE data2='xxx')
AND attname in ('att_name1','att_name3','att_name6','att_name4','att_name5','att_name6');
ID ATTNAME ATTVAL
===============================
1970 att_name1 123
1970 att_name2 abc
1970 att_name3 1234
1970 att_name4 def
1970 att_name5 1134
1970 att_name6 ghj
9812 att_name4 134
9812 att_name5 1436
9812 att_name3 156
9812 att_name1 187
9812 att_name2 179
9812 att_name6 1809
77 att_name1 1980
77 att_name5 1867
77 att_name3 174
77 att_name4 1345
77 att_name2 1345
77 att_name6 1345
but I don't know how to format the output comma limited in certain order. (or if this is the best way of getting the data out)
Would someone have idea how this could be done?846954 wrote:
Thanks Frank!
I got much further now :).
I've got Oracle 10g So I used the "SYS_CONNECT_BY_PATH" for my query.
Now I get the output in the format I want, however, it comes out in the order that the attributes are (which is pretty random).The values you posted are in order: 'attval1' < 'attval2' < ...
So I'm using this now(had to use "|" as separator because SYS_CONNECT_BY_PATH would not work with comma due to some of the attval having comma in them ):The values you posted don't contain and commas.
You're hiding what the problem is. It would really help if you posted actual data. It always helps if you post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data.
Assuming you really have something that has to be in a certain order, and that order is not based on anything in the values themselves, then DECODE might be a good way to do it. Storing the sort value in a table might be even better.
It looks like you were using an Oracle 9 exanple. In Oracle 10, using SYS_CONNECT_BY_PATH is simpler:
SELECT id
, LTRIM ( SYS_CONNECT_BY_PATH (attval, '|')
, '|'
) AS attvals
FROM (
SELECT id
, attval
, ROW_NUMBER () OVER ( PARTITION BY id
ORDER BY DECODE (...)
) AS curr
WHERE id IN (
SELECT id
FROM table_1
WHERE data2 = 'xxx'
AND attname IN ('attname1','attname2','attname3','attname4','attname5','attname6')
WHERE CONNECT_BY_ISLEAF = 1
START WITH curr = 1
CONNECT BY curr = PRIOR curr + 1
AND id = PRIOR id
;You don't need two almost-identical ROW_NUMBERs; one will do just fine. -
Sqlplus set statement:format the output without specifying every col length
Hi ppl,
i am writing below query inside a shell script. Is there any way to format the output of sqlplus without providing the name of all the columns that we are going to output. for example, in below code i have specified the column width of the columns i want to output. but if the number of columns is large (or when we want to do a select * from...) then it becomes tedious to write all of them. Is there any way i can define display length all the columns to be of same size.. or at least all the number columns of one size, char columns of one size etc...
sqlplus -sa/passwd@db_name << EOF
SET ECHO ON;
SET HEADING ON;
COLUMN USERNAME FORMAT A20;
COLUMN USER_ID FORMAT A20;
COLUMN PASSWORD FORMAT A20;
spool filename.txt
some qry... ;
exit
EOFThanks
Edited by: KnockTurnAll on 25 Oct, 2010 10:41 PM
Edited by: KnockTurnAll on 26-Oct-2010 04:25My SQL*Plus is a bit rusty, but I don't think you can for characters. You can set NUMWIDTH for a default size for numeric columns.
You could write a small bit of SQL to generate the required column definitions. You could even hit ALL_TAB_COLUMNS to generate a generic 'set every column width' file and run it as a separate sql script in your main script. Not sure if there is an upper limit on the number of Columns you can define.
Back in the day when we did everything with SQL*Plus scripts, we had a standard columns file that we called in all our scripts, just for this purpose.
Carl -
How to send a binary output from ni daq 6009
I am trying to get a binary output from ni daq 6009 to make the selections of a multiplexer.
I am trying to make the selection directly from the labview program.
Please help me in getting this binary output from ni daq 6009 to do the selectionTry something like this.
I'm not a fan of daq-assistant express vi's... use the primitives. Create the task outside the main structure, pass that task inside the loop and do a write where needed. Close the task after the main loop. This improves speed and labview performance.
Attachments:
ocelot.png 43 KB
ocelot.vi 21 KB -
I'm playing around with a small app that will save mysqldump output to file.
I managed to get it working, except when there's binary data on blob fields.
So, if I run from a console:
mysqldump -h server -u uni testdb > /tmp/test.1sql
and then the program listed below, I get excessive garbage in the binary fields and file sizes grow up:
-rw-r--r-- 1 nobody nobody 4535097 Aug 20 14:36 /tmp/test1.sql
-rw-r--r-- 1 nobody nobody 6493448 Aug 20 14:51 /tmp/test.sql
So, I tried executing with the --hex-blob flag in the mysqldump command, but in this case I've to pay the extra size cost:
-rw-r--r-- 1 nobody nobody 7131966 Aug 20 14:47 /tmp/test1.sql
As you will see, I'm grabbing the contents through an InputStreamReader
and then I write they with OutputStreamWriter. I didn't choose execute the command and save the file by the console 'cause I would prefer know what's going on, count bytes, showing a progress or whatever...
I would like to know how could I grab the binary output of the command ?...
It seems like the sh command is not binary...
Thank you!
This is the code:
class StreamGobbler extends Thread
InputStream is;
String type;
String Filename;
StreamGobbler(InputStream is, String type,String Filename)
this.is = is;
this.type = type;
this.Filename=Filename;
public void run()
try
PrintWriter out;
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
if (type=="ERROR") {
FileWriter outFile = new FileWriter("/tmp/error.log");
out = new PrintWriter(outFile);
String line=null;
while ( (line = br.readLine()) != null)
if (type=="ERROR") {
System.out.println(type + ">" + line);
out.println(line);
} else {
out.println(line);
out.close();
} else {
// FileWriter outFile = new FileWriter(Filename);
// out = new PrintWriter(outFile);
FileOutputStream fos = new FileOutputStream(new File(Filename));
OutputStreamWriter outs = new OutputStreamWriter(fos,"UTF8");
int len = 512;
char buf[] = new char[len];
int numRead;
while ((numRead = isr.read(buf, 0, len)) != -1)
outs.write(buf, 0, numRead);
outs.close();
} catch (IOException ioe)
ioe.printStackTrace();
public class mxdump {
public mxdump(String Cmd) {
try {
Cmd="/bin/bash /usr/bin/mysqldump -h server -u uni testdb";
/* String cmd[]={"sh", "-c",Cmd,""} ; //"mysqldump";
ProcessBuilder pb=new ProcessBuilder(cmd);
System.out.println("Start");
pb.start();
System.out.println("Termino"); */
String cmd[]={"sh", "-c",Cmd,""} ;
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR","");
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT","/tmp/test.sql" );
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
catch(Throwable t)
//System.out.println(e);
t.printStackTrace();
}Don't use Readers and Writers on binary data. Use Streams.
Maybe you are looking for
-
Cannot get URL web part filter to pass Parameter to List web part
How do I wire an out-of-the-box URL web part filter to a SharePoint 2013 list (or "app" as renamed in 2013) web part when the list has a parameter? My SharePoint list uses a parameter because it needs a Contains filter, as in <Where> <Cont
-
At the present time I'm using a Macmini in my taxi cab to play converted Karaoke CD+G files for my customers who like to participate in Cabaraoke. I also want to use it to record the performances. I'm currently using a Sony laptop with a web camera,
-
Creating java sockets behind proxy servers.
Hi, I am trying to create a socket to an external server(i.e. a public server) from behind a proxy firewall, but the socket creation statement throws an IO exception. Can someone please let me know how to create sockets using proxy servers. TIA Shish
-
Upgrading to 802.11n on older Mac Mini
I have 2007 802.11a/b/g Mac Mini Intel Core 2 Duo and a few questions: 1) How can I get 802.11n on this machine? 2) How much improvement will I see going from a/b/g to n? 3) Will this enabler do the trick? http://store.apple.com/us/product/D4141ZM/A
-
Query Engine Error 'crdb_b1.dll'
Can anyone help me with this error. I am trying to load crystal report for SAP B1 with data coming from stored procedure from vb.net