Binary-Value String to Float
Hi,
If I have a String which looks something like the following -
"1010"
how could I convert that to an integer 10 ?
Regards,
Gary
class Test{
public static void main (String args[]) {
String myString = "101010";
int myStringSize = myString.length();
int sum = 0 ;
int count=0;
for (int i = myStringSize-1;i>=0; i--) {
sum += (Math.pow(2,i))*Integer.parseInt(myString.charAt(count)+"");
count++;
System.out.println(sum);
}
Similar Messages
-
Hi,
I want to convert binary value to string format. How can i do that if possible please give me sample code.?
One more question is i want to do reverse thing also that is convert string value to binary format.?
Waiting for replyThere are methods in Integer, Long etc for transforming to binary.
I think there are probably also methods to go from binary to an int. Check out the JavaDoc -
Assigning a hex value to a variable and getting binary value of a variable.
I try to develop java programs and I need to do a conversion unicode to EBCDIC and vice versa.
How can I assign hex values to variables to build UTF-EBCDIC and EBCDIC-UTF table and get hex or binary value of data to compare it to value of in the table?
I did a conversion like this with PL/1 before. I do not know how can I do it with Java. Because I am new to Java.
Thank you in advance.I will run java code in mainframe and java uses
unicode for data in default and mainframe environment
is EBCDIC. So I have to translate the data from
unicode to ebcdic.I said I think String supports EBCDIC encoding...
String ebcdic = new String(ebcdicBytes, "Cp500");
http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html -
Need to convert a binary value into decimal
Hi i need to convert a binary value which i would be getting as a string object to a decimal value......need code for the same
Check Integer.parseInt
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#parseInt(java.lang.String,%20int) -
Assigning a binary value to an integer
Hi, I am trying to assign a binary value in my program to an integer. In some assembly languages you would do the following:
mov a, 00010101b
for binary and for hex:
mov a, 0E2h
In java, you can assign a hex value with:
int a=0x3F;
What should I do to assign a binary value? Is it possible?
Regards... Martin SchmiedelThe static method parseInt in the java.lang.Integer class can be used to convert a String representing a binary number into its decimal integer value. In addition to the string representing the number, you also pass in an integer representing the radix, which for binary would be 2, hex would be 16, etc. So for example:
int x = Integer.parseInt("00010110", 2);
Is that what you're trying to do? Cheers,
Chris -
Binary Values unreadable - Database corrupt?
Hi,
I'm experiencing a really weird problem here, I have a table with some varchar columns and two binary columns. What I do now, is to select data from it via Python with the following select statement:
select * from torder where customerid=1624 order by torderid desc
What happens is, that only for this customerid some binary data is missing, they contain an empty string. If I do the select like this:
select * from torder where customerid=1624 order by torderid
It does work, the data is there. With this, it works too:
select * from torder order by torderid desc
So it seems, the combination of "customerid=1624" and "desc" somehow corrupts the results.
What's furthermore interesting is, that when I delete the last inserted row of the result, it works, and if I add a new one, it's broken again.
I could not check if the error is Python-related or not, as I found no way to retrieve/display the binary data in sqlcli, as it displays only something like 0x8002637A6F70652E6931 , but I doubt that this has something to do with Python.
Any clues of how to fix this?
My database version is Kernel 7.6.06 Build 003-121-202-135 | X32/LINUX 7.6.06 Build 003-121-20
2-135
Previously, I had 7.6.03 and updated it to the above version, hoping that this would fix the problem, but it did not.
Best Regards,
Hermann HimmelbauerOk, first many thanks for your quick reply. I did not answer at first as the problem magically went away. But unfortunately the problem is back today.
<p/>
The DDL statements look the following, there are no indexes on the table:
<p/>
<pre>
CREATE TABLE torder (
torderid INTEGER NOT NULL DEFAULT SERIAL,
creation_date TIMESTAMP,
transfer_date TIMESTAMP,
signed_date TIMESTAMP,
signed_with VARCHAR(3) CHECK (signed_with in ('TAN', 'BKU', 'MAN') OR signed_with IS NULL),
revocation_date TIMESTAMP,
done_date TIMESTAMP,
formdata LONG BYTE NOT NULL,
trans_function VARCHAR(30) NOT NULL CHECK (trans_function in ('do_bank_transfer', 'do_bank_collection',
'do_cheque_transfer', 'do_cash', 'do_cashdraw')),
trans_type VARCHAR(30) NOT NULL CHECK (trans_type in ('national','sepa','international')),
applet_location VARCHAR(35),
errors_text VARCHAR(100),
errors LONG BYTE,
customerid INTEGER,
dbuserid INTEGER,
torder_periodicid INTEGER,
PRIMARY KEY (torderid),
FOREIGN KEY(customerid) REFERENCES kunde (kundeid),
FOREIGN KEY(dbuserid) REFERENCES dbuser (dbuserid),
FOREIGN KEY(torder_periodicid) REFERENCES torder_periodic (torder_periodicid)
</pre>
<p/>
The insert statements look the following (They are copied out of the SQLAlchemy SQL log), one can see that the binary values are inserted here:
<p/>
<pre>
INFO:sqlalchemy.engine.base.Engine.0x...d110:INSERT INTO torder (creation_date, transfer_date, signed_date, si
gned_with, revocation_date, done_date, formdata, trans_function, trans_type, applet_location, errors_text, err
ors, customerid, dbuserid, torder_periodicid) VALUES (now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INFO:sqlalchemy.engine.base.Engine.0x...d110:['20091027113506345604', None, None, None, None, '\x80\x02}q\x01(
U\x0bcharges_forq\x02U\x04bothq\x03U\x05dcodeq\x04U\x0588888q\x05U\x0ccurrency_isoq\x06U\x03EURq\x07U\x06valut
aq\x08K\x00U\x11foreign_acc_name1q\tU\x11Foreign Account 2q\nU\x0cacc_payer_noq\x0bX\t\x00\x00\x00999111110q\x
0cU\ttextlinesq\r]q\x0e(U\x0c1st transferq\x0fU\tMultilineq\x10U\x0bFor testingq\x11eU\x06amountq\x12cdecimal\
nDecimal\nq\x13U\x071000.00\x85Rq\x14U\x0cacc_benef_noq\x15X\t\x00\x00\x00888111110q\x16U\x11foreign_acc_name2
q\x17U\x0bfor Testingq\x18u.', 'do_bank_transfer', 'national', 'url:test_transfer', None, None, None, None, No
ne]
</pre>
<p/>
All rows are inserted with binary data, so it's never NULL and it's also never set to an empty string ('').
<p/>
But when reading back the rows, some binary values are an empty string.
<p/>
The following Python code illustrates the problem:
<pre>
import sapdb.dbapi
def true_false_result(result):
if result:
return 'Bug begins'
else:
return 'Bug ends'
def check_bincols(bdb, sqlcmd):
print "----
print "QUERY: %s" % sqlcmd
print "----
bdbc = bdb.cursor()
bdbe = bdbc.execute(sqlcmd)
bug_occured = False
stored_bin_result = False
while 1:
row = bdbe.fetchone()
if row is None:
break
Now check if the binary data results to an empty string,
This should never happen (= the database bug)
bin_result = (row[7]() == '')
if bin_result != stored_bin_result:
bug_occured = True
print "Toggle to %s at torderid %s" % (
true_false_result(bin_result),
row[0])
stored_bin_result = bin_result
if not bug_occured:
print "No Bug for this query"
bdbe.close()
bdbc.close()
#bdb.close()
if __name__ == '__main__':
bdb = sapdb.dbapi.connect('USER', 'PASS', 'DBNAME', 'LOCALHOST')
First try the original query, which results in a bug
sqlcmd = 'select * from torder where customerid=1624 order by torderid desc'
check_bincols(bdb, sqlcmd)
This query normally is bugfree
sqlcmd = 'select * from torder where customerid=1624 order by torderid'
check_bincols(bdb, sqlcmd)
This query has a bug, too
sqlcmd = 'select * from torder order by torderid desc'
check_bincols(bdb, sqlcmd)
But this one not
sqlcmd = 'select * from torder order by torderid'
check_bincols(bdb, sqlcmd)
This triggers the bug, too, which is curious as there's practically no ordering
sqlcmd = 'select * from torder where customerid=1624 order by customerid desc'
check_bincols(bdb, sqlcmd)
So, it seems that the bug occurs only when using "DESC" for descending
ordering.
</pre>
<p/>
The output of this program is:
<p/>
<pre>
QUERY: select * from torder where customerid=1624 order by torderid desc
Toggle to Bug begins at torderid 1355
Toggle to Bug ends at torderid 582
QUERY: select * from torder where customerid=1624 order by torderid
No Bug for this query
QUERY: select * from torder order by torderid desc
No Bug for this query
QUERY: select * from torder order by torderid
No Bug for this query
QUERY: select * from torder where customerid=1624 order by customerid desc
Toggle to Bug begins at torderid 1355
Toggle to Bug ends at torderid 582
</pre>
<p/>
So, it can be seen that the problem occurs ONLY when using descending ordering. Moreover it's interesting that the result for "select * from torder order by torderid desc" is sometimes buggy, sometimes not, which seems to be related if someone inserted some more rows or not. What's furthermore interesting is the last query, as there the order is applied to "customerid", which is the very same for every row, so there is no ordering and the bug occurs here, too.
<p/>
All this happens on my production instance. I have a testing environment, where I imported the very same data set (same database version etc.) and there is no such problem (for now), so it's quite complicated to nail down the problem further as I cannot easily disrupt the availability of the production instance.
<p/>
All I could do for now is not to use the "DESC" command and reorder the data in my application, but that is really suboptimal as I have to keep all results in memory.
<p/>
Any help is really appreciated!
<p/>
Best Regards,<BR>
Hermann Himmelbauer
<p>
Update: I tried the same query with the following code with C++ / SQLDBC (I modified one of the SQLDBC examples):
<p>
<pre>
First you have to include SQLDBC.h
#include "SQLDBC.h"
#include <stdio.h>
typedef struct ConnectArgsT {
char * username;
char * password;
char * dbname;
char * host;
} ConnectArgsT;
static void parseArgs (ConnectArgsT * connectArgs, int argc, char **argv);
using namespace SQLDBC;
Let start your program with a main function
int main(int argc, char *argv[])
ConnectArgsT connectArgs;
parseArgs (&connectArgs, argc, argv);
char errorText[200];
Every application has to initialize the SQLDBC library by getting a
reference to the ClientRuntime and calling the SQLDBC_Environment constructor.
SQLDBC_IRuntime *runtime;
runtime = SQLDBC::GetClientRuntime(errorText, sizeof(errorText));
if (!runtime) {
fprintf(stderr, "Getting instance of the ClientRuntime failed %s", errorText);
return (1);
SQLDBC_Environment env(runtime);
Create a new connection object and open a session to the database.
SQLDBC_Connection *conn = env.createConnection();
SQLDBC_Retcode rc;
rc = conn->connect(connectArgs.host, connectArgs.dbname,
connectArgs.username, connectArgs.password);
if(SQLDBC_OK != rc) {
fprintf(stderr, "Connecting to the database failed %s", conn->error().getErrorText());
return (1);
printf("Sucessfull connected to %s as user %s\n",
connectArgs.dbname, connectArgs.username);
Create a new statment object and execute it.
SQLDBC_Statement *stmt = conn->createStatement();
rc = stmt->execute("select * from torder where customerid=1624 order by torderid desc");
if(SQLDBC_OK != rc) {
fprintf(stderr, "Execution failed %s", stmt->error().getErrorText());
return (1);
Check if the SQL command return a resultset and get a result set object.
SQLDBC_ResultSet *result;
result = stmt->getResultSet();
if(!result) {
fprintf(stderr, "SQL command doesn't return a result set %s", stmt->error().getErrorText());
return (1);
Position the curors within the resultset by doing a fetch next call.
while (1) {
rc = result->next();
if(SQLDBC_OK != rc) {
break;
//fprintf(stderr, "Error fetching data %s", stmt->error().getErrorText());
//return (1);
char szString[30];
char szString1[3000];
SQLDBC_Length ind;
Get a string value from the column.
rc = result->getObject(1, SQLDBC_HOSTTYPE_ASCII, szString, &ind, sizeof(szString));
if(SQLDBC_OK != rc) {
fprintf(stderr, "Error getObject %s", stmt->error().getErrorText());
return (1);
rc = result->getObject(8, SQLDBC_HOSTTYPE_ASCII, szString1, &ind, sizeof(szString1));
if(SQLDBC_OK != rc) {
fprintf(stderr, "Error getObject %s", stmt->error().getErrorText());
return (1);
printf("%s %s\n", szString, szString1);
Finish your program with a returncode.
return 0;
static void parseArgs (ConnectArgsT * connectArgs, int argc, char **argv)
setting defaults for demo database
connectArgs->username = (char*)"USER";
connectArgs->password = (char*)"PASS";
connectArgs->dbname = (char*)"MYDB";
connectArgs->host = (char*)"localhost";
use values from command line
if (argc > 4) {
connectArgs->host = argv [4];
if (argc > 3) {
connectArgs->dbname = argv [3];
if (argc > 2) {
connectArgs->password = argv [2];
if (argc > 1) {
connectArgs->username = argv [1];
</pre>
<p/>
This works!! So it seems, that the problem is related to the Python module, which is interesting, as adding "DESC" should not be any difference to it. I personally suspect that there are some memory leaks in the code, which result in this strange behavior.
<p/>
Any suggestions?<p/>
Best Regards<br>
Hermann Himmelbauer
Edited by: Hermann Himmelbauer on Oct 28, 2009 12:51 PM
Edited by: Hermann Himmelbauer on Oct 28, 2009 12:55 PM -
How do I convert from String to float?
Hi,
you can use a Double for example - assuming value is that string to parse
float f;
try { Double d = new Double(value); f = d.floatValue(); }
catch (NumberFormatException e) { f = 0.0; } // error - string value could not be parsed
// here use your float fHope, that helps
greetings Marsian
P.S.: the Double class is usefull for that, because you also can get intValue(), doubleValue() or longValue() out of it for example. The StreamTokenizer for example parses numbers also only to double. -
Losing the leading zero in binary values
Hi all,
I�m currently creating some basic examples of bitwise operations and I�ve just noticed that I�m losing the leadnig zero of a binary value ( e.g.
decimal 1 (expecting to see bin of 0001) is manifesting as 1
decimal 16 (expecting to see bin of 00010000) is manifesting as 10000
below is a full example
import static java.lang.Integer.*;
public class BitExample {
public static void main(String[] args) {
System.out.println(
toBinaryString(0x1) + '\n' +
toBinaryString(0x16) + '\n' +
toBinaryString(0x6a) + '\n' +
toBinaryString(0x80)
I can see I�m missing something, but not sure what. Can you help?
Many Thanks
Gileswhich obviously returns a very different resultNo it does not ... let's translate the example to decimal (with additions instead of bitwise operations, but that doesn't change anything:
1234 +
0001
1235and
1234 +
1
1235both notations are correct, aren't they? Now the second one doesn't look so nice (and usually the 1 should be right-aligned to be easily readable, but it isn't wrong, because of this.
The same is true for binary operations. The problem is, that while learning bitwise operations it's easier to unserstand if you always write the leading zero (as you do in your example). -
Convert string to floating-point
Hi all,
..very basic question, but I tryed it for hours and only received short-dumps
<b>How can I convert a string into a floating-point number?</b>
Kind regards,
Stefanhi
try this
to convert string to float.
data : a type f,
s type string value '1.023'.
a = s.
write :/ a.
to convert float to string.
data : a type f value '1.023',
s type string.
s = a.
write : s. -
Hi all
Consider that I have a string in hex like this:
3020058020C00004Now I wanna convert it to binary, then I wanna have each digit single. For example, binary value for above string is:
11000000100000000001011000000000100000110000000000000000000100And I wanna have
1
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
1
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0How can I achieve this?String s_hex = "3020058020C00004";
String s_bin = Long.toBinaryString(Long.parseLong(s_hex, 16));
for(int i = 0;i<s_bin.length();i++)
System.out.println(s_bin.charAt(i)); -
Retrieving empty values from multi value string in user profile custom properties
Hi,
I created a webpart to save and retrieve data from custom properties. I use the code below to get the stored data:
for (int i = 0; i < profile[property].Count; i++)
Item = profile[property][i] == null ? string.Empty : profile[property][i].ToString();
list.Add(Regex.Split(Item, @"\,\#"));
Nothinig special about it.
In my development environment, it works fine. The problem is in my UAT environment. I'm facing an issue that i hope someone has been through. When the custom property is a multi value string type, it returns a empty string. I tested with HTML and single
value fields and it works fine.
Independently of the field type, it saves the data all right.
Can anyone help me?
Thanks!!Thanks, Chitvan Jain.
I did as you suggested, but nothing changed. The problem is that profile[propname] comes already blank when using multi value property, even if there is data to be retrieved.
One funny thing is that, somehow the code manages to count the number of values there is in the property. Only the data is missing. We can see the exact number of column, cause i check if there's the right number of data, if there isn't, i add up a empty
string on the grid cell, but only for viewing. The empty string is not stored in the property. -
po 100 pc
delivered 50 pc movement type 101
stock type unrestricted
now once i post the delivery in MIGO
system debit stock(BSX) account and credit GR/IR account
my question is can anyone tell me the complete chain of valuation and account assignment including the value string
i mean to say how the system is searching out this g/l/ accounts
please provide the link with value string
I AM CLEAR WITH THIS CHAIN GIVEN BELOW BUT I WAN TTO KNOW HOW movement type affects this chain
VALUATION AREA 1000
valuation grouping code AX
CHART OF ACCOUNT INT
BUSINESS TRANSACTION BSX
VALUATION CLASS 4400
Edited by: baxter jas on Jan 11, 2008 10:01 AMDear Baxter,
Answer for your Question.
1. In Good receipt System Generate 2 - Document.
( A. Material Document , B . Accounting Document.)
2. BSX or Store Account or Material Name Dr.
Gr / Ir Account Cr.
3. In MIRO also System Generate 2 - Document.
( A. Material Document , B . Accounting Document .)
4. Now Gr / Ir Account Dr.
Vendor Account Cr.
After MIRO System Cancel the GR / IR Account.
Now BSX or Store Accoutn or Material Dr
Vendor Account Cr.
Next Question of your's how system determine GL Account.
Answer.
1. Each and Every material have Own Valuation class.
2.Every Valuation Class Link with Gl Account.
3.Valuation Class and G.L Account Link With
Valuation Grouping Code.
4. Valuation Grouping Code Link With Valuation area.
5. Valuation area link with Company Code.
6. Comany Code Link with Chart of Account.
I Think it is some what Helpful for You.
Regards,
Rajan. -
Movement type and Value string
Hi,
I have copied movement type 101 to Z02. Is it possible to change the value String from WE01 to something else. My purpose is to post to a different account instead of GRIR while MIGO for free goods. So please don't suggest me to change in OBYC as the change is going to effect every MIGO which we don;t want to happen. Any ideas?
ThanksThe value strings contain keys for the posting transactions that can
lead to G/L account updates in the case of an FI-relevant posting. These
value strings are predefined by SAP. You cannot change value strings or
the transactions they comprise in Customizing. For each of these posting
transactions, you can set up automatic postings in dependence on the
other influencing factors.
The value string controls the process of G/L account determination for
transactions/events of the movement type (see unit Valuation and
Account Assignment), whereas the quantity string controls the updating
of the material master fields.
In SAP R/3, the value string WA01 is assigned to various goods issues
and other goods receipts. Further differentiation in the automatic
account determination process for these different movements is
accomplished via the account grouping code. -
Hi all.,
I want to insert a very large binary value of about 40000 character into database table i have tried by using clob datatype and blob datatype but all my efforts where ended in vain..
So can any one help me on this......
Thanks In advanceYou should use the dbms_lob package.
RTM first, then ask. -
Memory leak in "get property value (string)" ?
Hi,
I'm not sure which forum to post this to because it involves a combination of labview and teststand. The error I'm getting is more teststand related so it is here.
In our application, we have a labview queued state machine launched by a teststand step using "launch vi asynchronously". In one of the states of this state machine, we are looping grabbing frames from a camera, querying a teststand using "get property value (string)", to overylay on the video on each frame. This is so when we post process the video, we can tell what step(s) teststand was performing (we are writing a status string to a property from teststand as well). Since this string has to be overlayed on the video for each frame to be visible when played back, this happens many many thousands of times over the multi hour test runs of the platform.
My problem is, after 22 hours or so of running, I get an error generated from the "get property value (string)", saying cannot create any more threads. The only thing wired to this tool in our vi is sequence context, which is passed in when the vi is launched from teststand. When opening the "get property value (string)" vi itself, it is very simple, consisting of a "aspropertyvalue" casting, reading of the string from the proprety, closing the aspropertyvalue reference, and exiting. It does not seem like there should be any "threads" being created here, except for perhaps the vi itself executing. But in that case I would assume the OS itself would clean up after itself.
BTW, the OS I am testing on is win7 x64. I did see this though running on our xp box once as well though, same amount of time. It is very repeatable. My next plan is to disable this get property value using a disable case, and run again, but I"m still wondering why this error is occurring. Any help or insight will be appreciated.
Thanks
David Jenkinson
Hi,I'm not sure which forum to post this to because it involves a combination of labview and teststand. The error I'm getting is more teststand related so it is here.
In our application, we have a labview queued state machine launched by a teststand step using "launch vi asynchronously". In one of the states of this state machine, we are looping grabbing frames from a camera, querying a teststand using "get property value (string)", to overylay on the video on each frame. This is so when we post process the video, we can tell what step(s) teststand was performing (we are writing a status string to a property from teststand as well). Since this string has to be overlayed on the video for each frame to be visible when played back, this happens many many thousands of times over the multi hour test runs of the platform. My problem is, after 22 hours or so of running, I get an error generated from the "get property value (string)", saying cannot create any more threads. The only thing wired to this tool in our vi is sequence context, which is passed in when the vi is launched from teststand. When opening the "get property value (string)" vi itself, it is very simple, consisting of a "aspropertyvalue" casting, reading of the string from the proprety, closing the aspropertyvalue reference, and exiting. It does not seem like there should be any "threads" being created here, except for perhaps the vi itself executing. There seems to be something going on behind the scenes of this get property value tool that isn't cleaning up after itself?
BTW, the OS I am testing on is win7 x64. I did see this though running on our xp box once as well though, same amount of time. It is very repeatable. My next plan is to disable this get property value using a disable case, and run again, but I"m still wondering why this error is occurring. Any help or insight will be appreciated.
Thanks
David JenkinsonHi David,
Have you tried just using property node | Method Nodes instead of using the VI. There should be no difference but I think that VI is polymorphic ie the input with change depending on what's wired to it eg string, double etc.
Regards
Ray Farmer
Maybe you are looking for
-
Remote not working - doesn't seem to be pairing problem - any other ideas?
Remote not working - Unpair does nothing - Status light solid/screensaver running - no response from status light when any button clicked on remote - new batteries in remote - only Apple remote in the house - anyone have a suggestion?
-
Hello! What is wrong with this code ? I can't see the column names. Regards Ilhan TABLES: ekko. TYPE-POOLS: slis. "ALV Declarations TYPES: BEGIN OF t_ekko, ebeln TYPE ekpo-ebeln, ebelp TYPE ekpo-ebelp, statu
-
Error importing from BIAR file (BO XI 3.0)
Dear BO community, I am using the BIAR tool for backup purposes. For my backup, I use a properties file as input which looks like the one shown below: action=exportXML exportBiarLocation=C:/Temp/BOBackup.biar userName=Administrator password=XXX CMS=X
-
Does Adobe Acrobat XI Std include Distiller?
Does Adobe Acrobat XI Std include Distiller?
-
Cannot install Snow Leopard on late 2006 MacBook
I have been trying to perform an erase and reinstall of this machine for my daughter to use. The ram had been upgraded to 2GB, and my son had it partitioned to run Windows also. There was never any problem with the machine -- I just bought him a ne