The length of an integer
Hello.
Just for couriosity I'd like to calculate the length of an int and by that I mean return the number of digits.
I know how to do this 'manually', but is there a method somewhere that looks a bit like this:
object.calcInt(47653);//returns 5Thanks in advance
Interesting. Nobody likes the log method even though it is 30% faster.
public class Garbage
public static final int FIRST_INT = Integer.MAX_VALUE - 10000;
public static final int LAST_INT = Integer.MAX_VALUE;
public static final int TESTS = 1000;
public static void main(String args[])
long divideTestTime = 0;
long stringTestTime = 0;
long logTestTime = 0;
DivideTest divideTest = new DivideTest();
StringTest stringTest = new StringTest();
LogTest logTest = new LogTest();
for (int i = 0; i < TESTS; i++)
divideTestTime += runTest(divideTest);
stringTestTime += runTest(stringTest);
logTestTime += runTest(logTest);
System.out.println("Divide-test Time: " + divideTestTime);
System.out.println("String-test Time: " + stringTestTime);
System.out.println("Log-test Time: " + logTestTime);
public static long runTest(Test test)
long start = System.currentTimeMillis();
for (int i = FIRST_INT; i < LAST_INT; i++)
test.lengthOf(i);
return System.currentTimeMillis() - start;
interface Test {
public int lengthOf(int i);
class DivideTest implements Test {
public int lengthOf(int i) {
int size = 0;
do {
size++;
i /= 10;
} while(i > 0);
return size;
class StringTest implements Test {
public int lengthOf(int i) {
return String.valueOf(i).length();
class LogTest implements Test
private static final double l210 = Math.log(10);
public int lengthOf(int i) {
return (int)(1 + (Math.log(0.5 + i) / l210));
}
Similar Messages
-
Server Exception : The data exceeds the length
Hi All,
I am updating a MDM record through API . modifyrecord . I am changing almost 50 fields in record and then modifying . I get an error , the data exceeds the length . How can i know which particular Field is giving error . It just says the data excced the length but which fields is not shown in error .How to get the field name .Hi Govind,
I assume u r using ABAP.
Check if the data type u have assigned for all the fields is correct.
Specially check for integer fields also.
MDM_GDT_INTEGERVALUE only takes data upto 4 bytes but if it exceeds this limit u need to use MDM_GDT_DOUBLE.
Server exception mostly happens when some parameter is not entered correctly.
Regards,
Neethu Joy -
Substring Function without the length!
I know I have seen this before, but cannot find it when searching.
I need to do something similar to the Substring function, where I start from position 4, but the length behind this position is variable. Due to the IDOC it only passes the value...
I think I possibly saw a UDF for this somewhere - unless I can use some standard mapping!
It is probably very simple - but it is late in the day and my eyes are square! = )
<i> I need a drink......</i>
Can anyone help?
Message was edited by:
Barry NeavesFor substring function, you have 1 input and 2 parameters (you set the parameters by double-clicking the function box).
I also didn't understand how you can pass the output of length function two 2nd parameter of substring function (since it is a parameter and not an expected input).
You could always create a UDF...
public String UDSubstring(String a,String b,String c,Container container){
int d = Integer.parseInt(b);
int e = Integer.parseInt(c);
if ((e == 0) && (a.length() >= d)) {
return a.substring(d);
else if ((e > d) && (a.length() >= e)) {
return a.substring(d, e);
else return "";
They don't bite, you know...
Regards,
Henrique.
<b>Edit:</b> followed by Michal's correction... -
How can I uses byte[] to represent the length of a message?
hihi,
I want to using 3-bytes to represent the length of a message that send over a socket,
I don't know how to using byte to represent the length, should I parse integer to byte?
thank youint length;
DataOutputStream dos = ...;
dos.writeByte(length >>> 16);
dos.writeByte(length >>> 8);
dos.writeByte(length & 0xff);But why 3? Why not 2 or 4 like everybody else? with DataOutputStream.writeShort() or writeInt()? -
Character semantics when setting the length of NVARCHAR2 field (Oracle 10g)
SQL> CREATE TABLE viv_naseleni_mesta (
2 naseleno_mjasto_id INTEGER NOT NULL PRIMARY KEY,
3 ime NVARCHAR2(15 CHAR) NOT NULL,
4 oblast_id INTEGER NOT NULL REFERENCES viv_oblasti(oblast_id),
5 grad CHAR NOT NULL CHECK (grad IN (0,1)),
6 de_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
7 de_update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
8 de_operator INTEGER DEFAULT NULL,
9 de_versija NUMBER(5,2) DEFAULT NULL
10 );
ime NVARCHAR2(15 CHAR) NOT NULL,
ERROR at line 3:
ORA-00907: missing right parenthesis
It seems that the DB does not accept the length of a field to be given in character
semantics. I have several sources that say it is possible, but is that
only possible in 11g?According to the docs, NCHAR and NVARCHAR2 types are always character-based. So specifying in CHAR doesn't make sense explicitly.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch3globenv.htm#sthref385
Cheers
Sarma. -
How to know the length of a Byte array?
how to know the length a byte array if it is an argument of the method, e.g.
public byte[] hash(byte[] data) throws Exception
I wanna store the length of data into a integer in the method of hash, but no idea how to get it
THanks!to conclude:
I am a newbie, I wanna know , those "System"
methods as well.What exactly does that have to do with your original question?
or instance:
System.arrowcopy() , where can I find the
definition also?You probably meant System.arraycopy. The documentation is called JavaDoc and for Java 1.5 (a.k.a. 5.0) it can be found here: http://java.sun.com/j2se/1.5.0/docs/api/index.html
If you've not yet found the API documentation, then I'm pretty sure you should start with some tutorials, they probably point to all the interesting documentation as well. -
Check length on a integer variable
I have a declared
int IntLength=1234;how can i check the length on this, how many letters there are?
you can use .length on string variables, but cant find out how do make it work on a integer.
sincerely has the previous poster said... maybe something like...
int i = 1234;
String s = ""+i;
System.out.println( "length = " + s.length() );or the illegible version
System.out.println( "length = " + ((""+1234).length()) ); -
How do i find the length of a string??
trying to use the substring, I know the beginIndex (in my case 10), but the string will vary in size and so i need to find the last character and set it as the endIndex, how do i do this?
public String substring(int beginIndex,
int endIndex)Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
Examples:
"hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"
Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.Hi
To substring the string where u know the begin index and want to extract till the end use the following function from the String class of the java.lang package
String substring(int beginindex);
String test = "Hello";
String xx = test.substring(1);
The Value stored in xx will be ello
This is in case u need till the end of the String
If wanna skip the last character u can
use
String substring(int beginindex,int endindex);
String test = "Hello";
String xx = test.substring(1,test.length()-1);
The Value stored in xx will be ell -
How is the length of a string calculated in Java? and JavaScript?
Hi all,
Do any of you know how the length of a string is being calculated in Java and JavaScript? For example, a regular char is just counted as 1 char, but sometimes other chars such as CR, LF, and CR LF are counted as two. I know there are differences in the way Java and JavaScript calculate the length of a string, but I can't find any sort of "rules" on those anywhere online.
Thanks,
YimWhat's Unicode 4 got to do with it? 1 characteris 1
character is 1 character.
strings now contain (and Java chars also) is
UTF-16 code units rather than Unicode characters
or
code points. Unicode characters outside the BMPare
encoded in Java as two or more code units. So it would seem that in some cases, a single
"character" on the screen, will require two charsto
represent it.So... you're saying that String.length() doesn't
account for that? That sux. I don't know. I'm just making infrerences (==WAGs) based on what DrClap said.
I assume it would return the number of chars in the array, rather than the number of symbols (glyphs?) this translates into. But I might have it bass ackwards. -
The length of the password entry field in the BEx Analyser
Hi,
The password is 8 characters in the BW system.
When users changing their newly assigned passwords. When logging into the BEx Analyser, and prompted to change the password, a password entry box is displayed, with an entry field longer then 8 characters. Some users are therefore entering passwords longer then 8 characters. This is fine when they first login, but when they try come back to the system, their logon fails.
Can something be done to restrict the length of the password entry field in the BEx Analyser?
Many Thanks
JonathanHi Jonathan
we are having the same problem - did you find a way to resolve this? I did not find any SAP notes referring to the issue.
Regards
Hayley -
The length of UUID key is invalid
I am trying to use the new oracle service registry but when i register a service through the business service control and try to create a datacontrol for it in JDeveloper i get the following error:
DCA-40002: The WSDL document is invalid due to the following reason: java.io.IOException: org.systinet.uddi.InvalidParameterException: The length of UUID key is invalid
Some of the installed sample services are working fine but when i try to register and use my own services i always get this error in JDeveloper.
Has anybody succeeded in generating data controls from jdeveloper for service registry entries?
Kind Regards,
Andre JochemsI've had a similar problem when trying to create a ws stub. Could this error message be misleading and the real issue is that the xsd referenced in the wsdl was not found ?
(just a thought) -
The length of the recording and exporting truncated
Hi there.
It's my first venture into GarageBand. I have just a few questions.
First, how can I tell the length of my recording without having to listen to the entire session? Dragging the indicator bar in the window to move it along takes a very long time, is there a quicker way to do this?
Second, I have been exporting my files to iTunes to burn CD's. I am seeing that the file get's shortened in the process. It's not just a small clip, but rather edits out over 15 minutes on one file. Any thoughts? I called Apple and they knew nothing.To determine the length:
- Switch the meter that shows bars and beats to minutes and seconds (by clicking on the clock icon).
- Scroll to the end of the song.
- Click into the timeline's ruler, and the cursor will be taken there, the meter showing the minutes and seconds.
As for the export: Do you see the little purple triangle in the timeline, pointing to the left? That's your End of Song marker. Does it sit at the right position? If not, move it there and try exporting again. And since this little ******* is playing tricks sometimes, a more exact way of exporting is using the circle function and setting the circle section exactly from the beginning to the end of what you want to export.
Oh, and by the way: How long is your recording? If it exceeds 999 bars, then GB will only export until bar 999, although your whole recording is still there.
Come back and tell us what you found out! -
The type and the length of the members of the structures
I am making the BC-XAL program.
Reading `XAL_Interface_Documentation_11.pdf', now I succeeded in "Reading All Saved Monitor Sets" and "Reading All Monitors of a Monitor Set". but I can't find the type and the length of the member of the Structure BAPITNDEXT, so I cannot get the Monitoring Tree of a Monitor.
where can I get any documents or information ?This is how it looks in my 46c system.
MTSYSID SYSYSID CHAR 8 0R/3 System, name of R/3 System
MTMCNAME ALMCNAME CHAR 40 0Alert: name of monitoring context
MTNUMRANGE ALTIDNUMRG CHAR 3 0Alert: monitoring type number range (perm., temp, ...)
MTUID ALTIDUID CHAR 10 0ALert: Unique Identifier for Monitoring Types (used in TID)
MTCLASS ALTIDMTCL CHAR 3 0Alert: monitoring type class (perf., single msg.,...)
MTINDEX ALTIDINDEX CHAR 10 0Alert: internal handle for TID
EXTINDEX ALTIDINDEX CHAR 10 0Alert: internal handle for TID
ALTREENUM ALTREENUM INT4 10 0Alert: MT Tree info: Number of tree
ALIDXINTRE ALIDXINTRE INT4 10 0Alert: Tree Info: Index of MT in Tree
ALLEVINTRE ALLEVINTRE INT4 10 0Alert: Tree Info: Level of MTE in Tree
ALPARINTRE ALPARINTRE INT4 10 0Alert: Tree Info: Index of Parent of MT in Tree
OBJECTNAME ALMOBJECT CHAR 40 0Alert: Name of Monitoring Object
MTNAMESHRT ALMTNAMESH CHAR 40 0Alert: Short Name of Monitoring Type
CUSGRPNAME ALCUSGROUP CHAR 40 0Alert: Customization: Name of Customization Group
DELIVERSTA ALDELIVSTA INT4 10 0Alert: MT Val: Delivery Status
HIGHALVAL ALVALUE INT4 10 0Alert: alert value (1 = green, 2 = yellow, ....)
HIGHALSEV ALSEVERITY INT4 10 0Alert: severity (alerts, monitoring type custom..)
ALSYSID SYSYSID CHAR 8 0R/3 System, name of R/3 System
MSEGNAME ALMSEGNAME CHAR 40 0Alert: name of monitoring segment
ALUNIQNUM ALAIDUID CHAR 10 0Alert: Unique Identifier to be used in AID (char10)
ALINDEX ALINDEX CHAR 10 0Alert: internal handle
ALERTDATE ALDATE DATS 8 0Alert: date
ALERTTIME ALTIME TIMS 6 0Alert: Time value in timeformat
DUMMYALIGN ALDUMMYC2 CHAR 2 0Alert: Dummy field. Purpose: Alignment of date/time 16 byte
LASTVALDAT ALDATE DATS 8 0Alert: date
LASTVALTIM ALTIME TIMS 6 0Alert: Time value in timeformat
LASTVALDUM ALDUMMYC2 CHAR 2 0Alert: Dummy field. Purpose: Alignment of date/time 16 byte
ACTUALVAL ALVALUE INT4 10 0Alert: alert value (1 = green, 2 = yellow, ....)
ACTUALSEV ALSEVERITY INT4 10 0Alert: severity (alerts, monitoring type custom..)
VALSYSID SYSYSID CHAR 8 0R/3 System, name of R/3 System
VMSEGNAME ALMSEGNAME CHAR 40 0 Alert: name of monitoring segment
VALUNIQNUM ALAIDUID CHAR 10 0 Alert: Unique Identifier to be used in AID (char10)
VALINDEX ALINDEX CHAR 10 0 Alert: internal handle
VALERTDATE ALDATE DATS 8 0 Alert: date
VALERTTIME ALTIME TIMS 6 0 Alert: Time value in timeformat
VALERTDUM ALDUMMYC2 CHAR 2 0 Alert: Dummy field. Purpose: Alignment of date/time 16 byte
COUNTOFACT ALCNTACTAL INT4 10 0 Alert: MT Val: Count of active Alerts
COUNTSUM ALCNTSUMAL INT4 10 0 Alert: MT Val: Sum of Alerts in MT
VISUSERLEV ALVISILEVL INT4 10 0 Alert: MTE type dev cust: Visible on user level (op,exp,dev)
TDSTATUS ALTDSTATUS INT4 10 0
Alert: MT: Type Def Status
Welcome to SDN.
Regards,
Rich Heilman -
Calculating the length of the longest side of a polygon
If you want to calculate the length of the longest side of a polygon -- for example a rectangle -- how can that be done using the standard geometrical functions of spatial in an oracle 10g2 database?
SDO_LENGHT delivers the outline of the polygon. If have looked at the LRS functions, but could not come up with a combination that delivers me what I am looking for. Any suggestion is appreciated.What do you see as the longest side?
Is that the longest stretch between 2 consecutive vertices?
If this is the case, this sql could be of help, which could need maybe some optimisation and extension (calculates straigth distance between 2 consecutive vertices).
select id, p_side_nr, p_side, p_side_length
from
select id, p_side_nr, p_side, sdo_geom.sdo_length(p_side, 0.005) p_side_length, max(sdo_geom.sdo_length(p_side, 0.005)) over (partition by id) max_p_side_length
from
select id, p_side_nr,
sdo_geometry(2002, NULL, NULL,
SDO_ELEM_INFO_ARRAY(1,2,1),
SDO_ORDINATE_ARRAY(startx, starty, endx, endy)
) p_side
from
select
startp.id, startp.x startx, startp.y starty, startp.v_id p_side_nr, endp.x endx, endp.y endy, endp.v_id
from
select s.id, t.id v_id, t.x, t.y
from your_table_name s, table(sdo_util.getvertices(geometry)) t
) startp
select s.id, t.id v_id, t.x, t.y
from your_table_name s, table(sdo_util.getvertices(geometry)) t
) endp
where startp.id = endp.id
and startp.v_id = endp.v_id - 1
) where p_side_length = max_p_side_lengthif you do not need the geometry of that longest side, you could follow Ivan's suggestion as a shortcut by using Pythagoras.
Edited by: lucvanlinden on Sep 2, 2008 7:48 PM -
I go to "clip adjustments" and change the length of a clip. It reverts back to original length. I've also tried to shorten it by moving the yellow "box" around a specific clip to shorten. It still reverts back to original length. Why?
Welcome to iMovie Discussions.
See my 2nd reply to 'getzcreative', here.
Maybe you are looking for
-
Middle click new search bar's search for with should open in a new tab.
Is there a setting anywhere to enable middle clicking on alternative search engines in the new search bar to open in a new tab.
-
Application collection deployment, once a day
I am trying to install an application to a collection of roughly 230 servers. However due to licensing, I only want this on the production servers. Therefore I have created a separate collection for test servers and put this as an exclusion collectio
-
IOS 5 OTA: Device query for mac address
Device query for attribute "MAC_ADDRESS_EN0" doesn't return any value on iOS 5. It use to work fine on iOS 4. Does anyone know the new attribute to query mac address on iOS 5. Appreciate any help. Thanks, Juzer.
-
Database Connectivity in JavaFX
How can i connect to database and perform CRUD operations using JavaFX?...
-
App for larger picture ID for OUTSIDE of phone?
I downloaded an App from Blackberry App World named "larger picture id's" thinking my contacts picture id's, when they call or text, would be bigger for the outside of the phone..but it only works if i keep my blackberry style phone open...is there a