short

Convert short to byte[] in Java

How can I convert a short (2 bytes) to a byte array in Java, e.g. short x = 233; byte[] ret = new byte[2]; ... it should be something like this. But not sure. ((0xFF << 8) & x) >> 0; EDIT: Also you can use: java.nio.ByteOrder.nativeOrder(); To discover to get whether the native bit order is big or small. In addition the follow...

Pointer type conversion: effect on buffer length?

Char is 1 byte unsigned short is 2 bytes So if I cast a char * to unsigned short *, will it change the length of the buffer? For example I am passing char * and length to a VUMeter function. The function casts the char * to unsigned short *: short* pln = (short*) buffer;` Now I loop through the buffer, so can I use same length which...

When using a unique alphanumeric string for a short url, is it better to store the created string in the database or encode/decode on the fly?

I want to create shortened links for specific pieces of content on my site. To view these pages now, I pull the relevant content via the content ID passed via GET (ie, mysite.com/content/?id=332). To obfuscate the ID, I want to use base64 to encode and decode it into a short alphanumeric string (like 34sa6), which I already know how to d...

What are some good, but short, programming books?

My personal definition of a "short" programming book is a book with less than ~500 pages, but YMMV. So if you have a different definition of a short book, feel free to post. If you can, please post the number of pages of the book you are recommending. General programming books and books about a specific area of programming are both welco...

Is wchar_t just a typedef of unsigned short?

for example, does: wchar_t x; translate to: unsigned short x; ...

How can I access a byte array as shorts in Java

I have a an array of byte, size n, that really represents an array of short of size n/2. Before I write the array to a disk file I need to adjust the values by adding bias values stored in another array of short. In C++ I would just assign the address of the byte array to a pointer for a short array with a cast to short and use pointer...

In java is it possible to pack a integer number that is expected not to be negative & be final (not overflow) into a short?

"Unsigned int" into a short and back. Is this possible? How to do it if so? Grrrr. I forgot how signed numbers are implemented. The question makes no sense. Thanks anyway. I was going to downvote myself, you can do it instead. ...

How to get short URL inside my iPhone app?

I need to get a short URL from a long one (that I made inside my app). I think that I already read about this, but I couldn't find it anymore here in SO. Anyone has a piece of code or directions to point this out? Best Regards ...

1-letter names for variables and functions in jQuery, JavaScript

Hi there, I was looking at Twitter's static scripts and noticed that all variables and functions where just 1 character long, why and how do they do this? Has it something to do with performance? If so, why don't they give all elements on their website these kind of short names, maybe 2 characters long instead of 1 to avoid any collisio...

How to find the timezone with "HNEC" short name?

My Android app is using this code to get the short name of the timezone in which the handset is located. String shortDisplayName = Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT); For my user in Strasbourg, France, shortDisplayName is "HNEC" (I haven't learned yet exactly which locale is in play). I'm tryin...

What is best compression scheme for very small data as1.66kBytes

this data is stored in an array (using C++) and is repitition of 125 bits each one varying from other also has 8 messages of 12 ASCII characters each at end..... Please suggest that should i use diffential compression within array and how? or i should apply some other compression scheme as whole onto the array? thanks in advance Regar...

Java HashSet and data type Short, incompatibility ?

Running this code: public class SomeSet { public static void main(String[] args) { Set<Short> s = new HashSet<Short>(); for (short i = 0; i < 100; i++) { s.add(i); s.remove(i - 1); } System.out.println(s.size()); } } Will print the value 100. Why does it pri...

Why do I get corrupt output on my file?

I have a simple program which I have compiled in both MinGW and Visual C++ 2008 Express, and both give an output file larger than 88200. When I set s = 0, both programs work as expected. What am I doing wrong? #include <fstream> using namespace std; int main(int argc, char *argv[]) { int i; short s; fstream f; f.op...

convert from short to byte and viceversa in Java

Hi there, I'm trying to convert a short into 2 bytes...and then from those 2 bytes try to get the same short value. For that, I've written this code: short oldshort = 700; byte 333= (byte) (oldshort); byte byte2= (byte) ((oldshort >> 8) short newshort = (short) ((byte2 << 8) + byte1); Sy...

How do I print a short as an unsigned short in Java

I have an array of short whose values range between 0 and the maximum value of a short. I scale the data (to display it as TYPE_USHORT) so that the resulting short values range between 0 and 65535. I need to print some of the scaled values but can't figure out how. The data are in an array and in a BufferedImage. ...

VB.NET Bit manipulation: how to extract byte from short?

Given this Short (signed): &Hxxxx I want to: Extract the most right &HxxFF as SByte (signed) Extract the left &H7Fxx as Byte (unsigned) Identify if the most left &H8xxx is positive or negative (bool result) ...

Ruby on Rails - generating bit.ly style uuids

Hello, I'm trying to generate UUIDs with the same style as bit.ly urls like: http://bit.ly/aUekJP or cloudapp ones: http://cl.ly/1hVU which are even smaller how can I do it? I'm now using UUID gem for ruby but I'm not sure if it's possible to limitate the length and get something like this. I am currently using this: UUID.generat...

php: number only hash?

In php is there a way to give a unique hash from a string, but that the hash was made up from numbers only? example: return md5(234); // returns 098f6bcd4621d373cade4e832627b4f6 but I need return numhash(234); // returns 00978902923102372190 (20 numbers only) the problem here is that I want the hashing to be short. edit: OK let ...

C#, sorting objects in list by Name

Hello, how could i sort objects in list by their name? Example: mapPart_1_0 mapPart_1_2 mapPart_1_4 mapPart_1_6 mapPart_1_8 mapPart_1_10 mapPart_1_12 mapPart_1_24 mapPart_2_1 mapPart_2_11 Big list continues... (somewhere in that list are missing that aper in sorted one) Into: mapPart_1_0 mapPart_1_1 mapPart_1_2 mapPart_1_3 mapPart_1_...

Testing short reads/writes handling

Good applications should expect short reads/write almost everywhere. But actually, for example, when reading small number of bytes from filesystem or from pipe short reads just [almost] never occur and defects in it's handling can remain undetected. How to test group of applications interconnected by pipes and sockets and reading and w...