Using 32 bit integers
I need to use a 32bit integer in my app, but Java Card only supports 16 bit integers. What's the best way of handling this? I've been trying to do it with a 4 byte array but I'm having problems add/subtracting. I've made the following function to adding two byte array integers together
public static byte [] intAdd(byte [] firstInt, byte[] secondInt) {
if (firstInt.length != 4 || secondInt.length != 4) ISOException.throwIt(ISO7816.SW_WRONG_DATA);
byte [] result = new byte[4];
byte carry = (byte)0x00;
for (int i=3; i>=0; i--) {
int tmp = firstInt[i] + secondInt[i] + carry;
byte[] tmpb = intToBytes(tmp);
result[i] = tmpb[3];
carry = tmpb[2];
return result;
It doesn't work properly because java treats each individual byte as a signed integer. Plus I think this is horribly inefficient.
797530 wrote:
public static byte [] intAdd(byte [] firstInt, byte[] secondInt) {
if (firstInt.length != 4 || secondInt.length != 4) ISOException.throwIt(ISO7816.SW_WRONG_DATA);
byte [] result = new byte[4];
byte carry = (byte)0x00;
for (int i=3; i>=0; i--) {
int tmp = ((short)firstInt[i] & 0x00FF) + ((short)secondInt[i] & 0x00FF) + carry;
byte[] tmpb = intToBytes(tmp);
result[i] = tmpb[3];
carry = tmpb[2];
return result;
Please you code tags when posting code.
In the code you have posted there is a memory leak and your card will run out of EEPROM eventually. You should only ever use the new keyword in your applet constructor or code that is only ever called from the applet constructor as there is (essentially) no garbage collector.
Similar Messages
-
DNG SDK thinks 0xFFFFFFFF is invalid white level for 32 bit integers
As discussed in another message the DNG SDK does not seem to be able to write floating point DNGs. Since I need higher dynamic range than a 16 bit sample I instead went for 32 bit integers.
This works, and I manage to create a file but when I run dng_validate on it it says the white level is invalid. The white level I have of course set to 0xFFFFFFFF to make use of the full 32 bit range. Looking into the code in dng_ifd.cpp where this test is made it seems like the default max white level is set to 65535.0 and the file's white level is compared against that, regardless if the sample type is 16 or 32 bit. This means that I can only make use of 16 bits of the 32 bit integer which seems kind of strange. Looking into the DNG spec I don't see anything there that forbids using the full 32 bit range of 32 bit samples. So this looks like a bug to me.
This is with version 1.4
the created file can be opened in Lightroom 4, so the only problem seems to be that dng_validate does not think its valid.
Message was edited by: torger76, removed clipping issue, that was a fault in my code.Hello Charles,
I would be concerned too if my MacBook Prowas running slowly. I found a couple of articles I recommend to help isolate and troubleshoot this issue.
I recommend reviewing this article first for possible causes of the slowness:
OS X Mavericks: If your Mac runs slowly
http://support.apple.com/kb/PH13895
You can further isolate the issue by determining if it is only happening in your user account or if it is happening system-wide:
Isolating an issue by using another user account
http://support.apple.com/kb/TS4053
Thank you for using Apple Support Communities.
Best,
Sheila M. -
Join two 8 bit integers and send via Serial Port
I am trying to join two 8 bit integers and send the result via the serial port.
I have a constant of hex value A that I need to join with a value from hex 0 - F (this is based on incoming data)
When I use the Join VI, and type cast to change from hex to string for Visa Write, I recieve hex 0A0F.
I have been able to use the hex 0-F with a case structure and then wire the corresponding constant ex A0 - AF.
This makes the program very cumbersome and labour intensive to change. I have 22 commands I have to respond to with the address of 0-F.
Currently, I have a Case structure that is selected with Message ID, then a case that is selected with subtype and then a case for address.
Therefore I have to create a constant inside of each address case for each message as the responses are different.
Thanks for any help
RobinGambin,
As I understand it, you want to take the two bytes, put them together,
and output the result as an ASCII string on the serial port. This
is easy. Simply convert each number to an ASCII string,
concatonate the two characters together, and send the resulting string
to the VISA write function. That's it! I have attached a VI
(ver. 7.1) that takes two hex numbers as input, converts them to ASCII,
concatonates the results, and outputs the 'command' string. Fell
free to modify this vi and use it as you see fit. I have left
extra terminals in case you want to add error input/output for data
flow, or whatever. Notice that the display for the concatonated
string is in '/' Codes Display mode. This is because 0A hex is
the newline character in ASCII. You should also check to make
sure that your VISA serial settings are not setup so that the newline
character is the termination character. If it is, the second
character may not be recognised. Hope this helps.
Roy
Attachments:
HextoCommand.vi 17 KB -
How to create a picture indicator from an array of 32-bit integers
My problem is simple. I have an array of signed 32-bit integers that represents image information. I want to display that information in a picture indicator on the front panel of my VI, but none of the picture indicators accept the array. What conversions or picture control do I need to use?
thanks!Try Draw Unflattened Pixmap.vi.
Lynn -
Hi everybody,
I have a very time consuming problem with opc programming in labview: I need
to write 16 bit integers with the labview opc client to the server - and I
don't know how to do this because of the limitation of the labview Vi's to
32 bit integers.
Any suggestion is very welcome.
Bernd SzyszkaWhat is the limitation? LabVIEW has 8,16, and 32 bit integers - both signed
and unsigned.
"Dr. Bernd Szyszka" wrote:
>Hi everybody,>>I have a very time consuming problem with opc programming
in labview: I need>to write 16 bit integers with the labview opc client to
the server - and I>don't know how to do this because of the limitation of
the labview Vi's to>32 bit integers.>>Any suggestion is very welcome.>>Bernd
Szyszka>> -
Does BI 7.0 use bit map join indexes?
I have seen several threads on SDN which show that SAP BI is using bit map indexes with Oracle database. However, it is not clear whether BI utilizes bit map join indexes or just bit map index. Bit map index is on a single table whereas bitmap join index is on a join of two or more tables.
It will make sense for SAP BI to use bit map join indexes with star transformations where a join is done among fact and dimension tables.> Thanks. Another question, are bit map indexes used both for F and E fact tables or just for F. I am not using real-time cubes (where SAP BI uses B-Tree indexes for F table to avoid dead locks).
Why don't you simply check this in your BI system yourself?
And, yes, of course it uses bitmap indexes for both fact table types.
E-fact tables are the same as F-Facttables except that they contain the compressed/rolled up data.
regards,
Lars -
Download Software Updates Wizard from the Internet - does it use BITS to do this?
I have a Primary Site Server at my Datacenter and I setup a temporary DP on a test Win 7 system. I initially was having timeout issues trying to deploy software updates to a group of test systems for my pilot deployment to this remote location from the DP
located at the Datacenter. So I decided to setup a temporary DP on a Win 7 system to see if this will help resolve the timeout issues.
My question is, when I download patches to the package located on the remote Win 7 DP does it use BITS to do this?
Exactly what is the process that occurs when this happens, or will the PatchDownloader.log file give the info I need? I have looked in the PatchDownloader.log file and nothing has appeared yet.
ThanksSo it sounds like I do in fact need to create a separate package just for that remote Win 7 DP then.
What I am trying to get at is this:
I have a very slow WAN link from the Datacenter to a remote site that I am running my second pilot deployment on (Pilot 2)
I have an existing package that I have been using for the last 4 months or so that I have been using for my first pilot deployment (Pilot 1)
I tried to deploy the software updates initially for Pilot 2 to my remote test systems, but they were timing out due to the constricted WAN bandwidth and the fact BITS traffic is being regulated with a packet shaper appliance device
Because of the timeout issues I was seeing in the WUAHandler.log and WindowsUpdate.log, I decided to first setup a simple Win 7 DP to see if this could resolve the timeout issues
I knew that the software updates that I wanted to deploy already existed in my "2014_Monthly_Patches-Datacenter" package, but I did not want to run the Distribute Content Wizard to deploy this entire package to my remote Win 7 DP across my very
slow WAN link and saturate the wire
So I re-downloaded the software updates again, but this time instead of having them download to the Package Source on my Primary Standalone Site server located in my Datacenter, I downloaded them to a new Package Source on the remote Win 7 DP instead and
I put them in a completely separate package named "2014_Monthly_Patches-RemoteSiteA"
What I want to know is if the steps I performed above necessary and accurate, because I do have such a slow WAN connection between the Datacenter and the remote site, or is there another way of doing this without creating the separate Package Source and
separate package on the remote DP? -
Hello,
Increasingly I am getting requests from legal site to download their video or Audio content using bit torrent. I have installed the lastest version on my iMac G5 but nothing downloads. Do I need to turn something on or off, I need help please.
Thank you
iMac G5 Mac OS X (10.4.6) 1 gig ramHi Brad,
The more ports you enable for torrents the faster your transfer speeds. Typically you can enable TCP 6881-6999 (range of ports). If you use MacOS X's built-in firewall, follow these steps.
1. Open System Preferences.
2. Click Sharing.
3. Select the Firewall tab.
4. Click the New... button.
5. Click the popup menu in the dialog that appears, and choose Other....
6. In the Port Number, Range, or Series field, enter 6881-6999.
7. In the Name field, enter BitTorrent (or any other identifying string.)
8. Click OK.
If you use any other firewall follow its instructions to enable TCP 6881-6999 (range of ports).
If you want to understand how it works, you can find a good FAQ&Guide here: http://btfaq.com/serve/cache/1.html
Macs running 9.x, Macs running 10.4.x, SGI workstations running Irix 6.5.xssion.
Message was edited by: fu -
New Article: Improving application performance using bit manipulation
Hi,
We've just published an article on how to optimise some kinds of algorithms using bit manipulation.
Regards,
Darryl.
Message was edited by: Darryl Gove to fix broken linkCR4E 2.0 currently uses 5 CPLs - 5 concurrent process license, which means it services up to five concurrent report requests. This isn't per-session, per-report, or per-user, but per-request (open report, next page, export).
So having 15 simultaneous users may lead to some requests being queued till a license is free.
For a more scalable solution, the recommendation is to go with a server-client solution like Crystal Reports Server Embedded or BusinessObjects Enterprise.
But to tune your CR4E app to see how much you'll be able to service, what I recommend is turning on Log4J logging to see where the performance is going.
Going from 2 sec to 30 sec between CR Designer (binary app) to CRJ (pure Java app) isn't out of performance expectations, but there may be ways to tune it.
For example, if you're doing replaceConnection or setTableLocation, you may just want to do it once to the rpt file during deployment, so you'd not need to change the connection info every time the report is run.
Saving to application context isn't something that CRJ is designed for - it's designed to have the ReportSource per-Session.
Sincerely,
Ted Ueda -
Displaying signed 8 bit integers using a data plug-in
Hi there,
I'm currently using DIAdem 10.1 and I'm writing a data plug-in in order to read binary data. What I'm missing is a data type "eI8" to read and display 8 bit signed integers. Obviously, to get the data into a channel, I have to use the data type eByte, but how do I make DIAdem display it as a signed value in the data portal?
Many thanks in advance!
Regards,
StefanHello Stefan,
you can use the method:
Value = Object.GetNextBinaryValue(eDataType)
eDataType
Aufzählung.
Bestimmt den Datentyp des auszulesenden Werts.
2 - eI16
16-Bit-Integer.
3 - eI32
32-Bit-Integer.
4 - eI64
64-Bit-Integer.
5 - eByte
Byte.
6 - eU16
16-Bit-Unsigned-Integer.
7 - eU32
32-Bit-Unsigned-Integer.
9 - eR32
32-Bit-Real.
10 - eR64
64-Bit-Real.
Regards,
Rebecca Fox
Applications Engineer
National Instruments -
Third Party U 64 Control, Used bits 25 most significant
I spent the whole day at work trying to work out some calculation and the simple fact that I dont know and could not find any literature on using x number of bits from a U64, I returned home with no results for today.
Dear Experts Please help. I have on the machine an endat encoder to measure the speed in RPM of the shaft of a motor. I used manufacturers provided RT vi to acquire the position data. This is a 25 bit encoder so the RT vi position indicator gives a 25 bit value. This value is acquired using a U64 indicator. I found that only the most significant 25 bits are used from this U64 indicator.
This 0 to 2^25 bit value ( 0 to 33554432) corresponds to 0 to 360. The manufacturer gave the following instructions to convert it into RPM.
Timed loop period to 1000 ms Take difference of the current position value from the previous position value and divide it by 2^24 and multiply by 60.
I can read the current position. Then use the shift register on the timed loop to read the previous position value. Both are acquired using U64. When I subtract the two, the results fluctuates as below.
The difference, some random value, the difference, some random value, some random value, the difference.
I dont know why this is occuring. When I can read the current and previous position values, why the difference is not a correct value. It looks to me that it is perhaps something to do with the bits of the U64 indicator.
Any comments will be much appreciated
Kind Regards AustinI think it would be sufficient to wrap the subtraction result back into 25 bits using quotient and remainder. Here's a quick draft. See if it works for you.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
Wrapper25.vi 12 KB -
I am running Vista. Updates are current. Recently installed Bid Defender security. Have reloaded Firefox 6 several times, Google Chrome also. both browsers say they are "waiting" for either the website, or some ad to respond much more often and longer than before. Any suggestions?
Sorry Tominique, great answer to the question I didnt ask. I know how to add data to my plan.
My point is, my usage pattern has changed little. yet I am using at a rate 5 times what I was before. And I rarely stream content so I know thats not it. And the times I do, does not coincide with those ridiculous usage figures.
I get that having more bandwidth will open a stream "wider" so to speak and cause more data usage in order to get better quality. However, in the case of Audio, that extra usage doesnt even come close to justifying these kinds of figures. Much less when posting at 4am when I am fast asleep.
And forgive me for being a bit curt, but does my post read like I needed to be told that using wifi will save me cell data usage? I know it was pretty long, but at least read it carefully before proposing something so mundanely simplistic.
And Brian68- Yup, I agree Spot on with you on song size. A 10mb song is a 10mb song. Doesn't matter how fast the stream is. I could see music being compressed, but it most definitely doesn't get any bits added just because the bandwidth opens up. lol What? VZW somehow upgraded my itunes match content from 256kb up to lossless? doubtful. -
Use bit.ly for audio link?
I just launched my first podcast. I'm hosting the .mp3 from an enjin.com website and they don't have any sort of click counter so I would like to create a bit.ly link to the files. Will iTunes (and RSS feeds) work fine if I use the bit.ly forwarding link for the GUID and Enclosure?
Thanks!No. You can use redirects for the media file (though it sometimes causes trouble so you need to be cautious about it) but the URL must have the media file extension - e.g. .mp3 - or iTunes won't recognize it as a media file and won't display the episode at all.
As to tracking downloads, Apple's help site mentions this:
http://www.apple.com/itunes/podcasts/specs.html#tracking
but from what you say it probably won't help you. If you submit your feed to Feedburner and have it submit its version to iTunes, it can provide tracking by referring the files through Google Feedproxy: however it's been reported that this can cause problems so again you may want to be cautious. -
Numeric_limits doesn't understand 64 bit integers
If you run the following code, you will find that Forte 6 Update 2 (patched) thinks that the maximum value of a 64 bit integer is zero. The same results with long long or unsigned long long.
#include <limits>
#include <iostream>
#include <inttypes.h>
using namespace std;
int main(int argc, char * argv[])
std::cout << "int32_t: " << numeric_limits<int32_t>::max() << std::endl;
std::cout << "uint32_t: " << numeric_limits<uint32_t>::max() << std::endl;
std::cout << "int64_t: " <<numeric_limits<int64_t>::max() << std::endl;
std::cout << "uint64_t: " <<numeric_limits<uint64_t>::max() << std::endl;
std::cout << "long long: " <<numeric_limits<long long>::max() << std::endl;
std::cout << "unsigned long long: " <<numeric_limits<unsigned long long>::max() << std::endl;
return 0;
}Results:
int32_t: 2147483647
uint32_t: 4294967295
int64_t: 0
uint64_t: 0
long long: 0
unsigned long long: 0It seems you see a zero return value because the default implementation of numeric_limits lacks definitions for these larger data types. The man page for numeric_limits(3C++) shows this. The list of specializations at the top omits the types for which a zero result is obtained. The zero return value is therefore a "false" condition.
This works with -library=stlport4, however, presumably because the STLport4 implementation has specializations for all of these types:
# CC -library=stlport4 -o test test.cc
# test
int32_t: 2147483647
uint32_t: 4294967295
int64_t: 9223372036854775807
uint64_t: 18446744073709551615
long long: 9223372036854775807
unsigned long long: 18446744073709551615
With FD6u2, you can follow the procedure in Chapter 12 of the C++ User's Guide to replace the default implementation with STLport or another 3rd-party
implementation.
- Rose -
FYI about wrapping 32-bit integers
This is a note for newbies, however, I have a question that came up writing this post that I'd appreciate any experts addressing. Please see the bottom of the post, "Code" Question.
I am not talking about wrapping a class around a primitive. I am talking about the low level issue of what happens internally to a 32-bit integer value as the bits wrap around either limit of the data type.
This is a FYI for noobs like me! Consider the following code:long bigValue = 53*52*51*50*49*48;
System.out.println(bigValue);Looks ok to us noobs, right? But the output this produces is -650,483,584 (I added the commas). When I did this I was puzzled for a bit, then I remembered that when you add to a value an amount that exceeds the upper limit of that type (subtract past the lower limit) the value can wrap. For example, a Java byte - an 8-bit type - has a range of -128 to 127. If I have a variable of type byte equal to 127 and add 1 to it, the result is -128! The bits inside wrapped around.
In my code sample, what is salient is that in Java an integer literal is always assumed to be an int - a 32-bit integer - which has a range of:-
-2,147,483,648 to 2,147,483,647. The resulting multiplication I was doing equals 16,529,000,000 which is out of range for an int, so it wrapped and gave me the negative value.
It didn't matter that bigValue was of type long. Java was looking first at the operations which contains integer literals; therefore it internally used an int to perform the multiplication, which caused the bit-wrapping. Fortunately, you can force Java to use a long value all the way through this computation by forcing the first literal to represent a long (a 64-bit value). Example:
long bigValue = 53L*52*51*50*49*48;
System.out.println(bigValue);
Notice the capital "L" after "53". That forced Java to read "53" as a long, and thereafter it continued to perform the multiplication steps on a long instead of an int, finally yielding the correct value to assign to bigValue.
...Just thought other newbies would appreciate the heads-up.
"Code" Question
When trying to write the second code snippet, the part "53L" would look like "53" in the preview. I could not figure out how to "escape" the "L" so it would show up. Anyone know how to do that?kajbj and vanilla_lorax...
Thanks for the explanation and "fix".
Have y'all had trouble with the B,
I,
U, and code buttons? Every time I
click on them I get an "Error on page" in the leftof
my browser's status bar....Try clearing your browser's cached files. It might
help.Nope, didn't help.
Maybe you are looking for
-
Does anyone knows what means "Table ZT_QM is not in nametab" when importing a transport request with this table Thank you in advance
-
MacMini Remote Hard Drive Home Directory Crashes For no Apparent Reason
Hello Hopefully someone here can help me fix this problem I've been having. BACKGROUND: I have my MacMini setup with a remote harddrive where i keep all of my movies, music and personal settings. I origionally copied my home directory over to the mac
-
Can't access iCal in iCloud.
Can't access iCal in iCloud. Reported to Apple. Any fixes?
-
How can I get my phone not to sync with my outlook calendar?
Can someone please help?
-
Dynamic text element (Text Symbols)
Hi, How can we make text element dynamic? Ex: If I want a text "Consider date g_date" where g_date is populated from program. Can I pass g_text like <b>text-001 g_text</b>? Thanks.