short

Dynamically generate short URLs for a SQL database?

萝らか妹 提交于 2019-12-13 16:42:05
问题 My client has database of over 400,000 customers. Each customer is assigned a GUID. He wants me to select all the records, create a dynamic "short URL" which includes this GUID as a parameter. Then save this short url to a field on each clients record. The first question I have is do any of the URL shortening sites allow you to programatically create short urls on the fly like this? 回答1: TinyUrl allow you to do it (not widely documented), for example: http://tinyurl.com/api-create.php?url

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

孤街醉人 提交于 2019-12-13 02:14:50
问题 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) 回答1: Uh... value & 0x00ff (value & 0xff00) >> 8 (value & 0xf000) >= 0 EDIT: I suppose you want the byte value and not just the upper 8 bits. 回答2: Extract the most right 0xxxff myShort & 0x00FF Extract the left 0xffxx (myShort & 0xFF00) >> 8 Identify if the most left 0xfxxx is positive or

When casting an int array to a short*, why does assigning a value to an element overwrite the entire integer?

江枫思渺然 提交于 2019-12-13 01:14:07
问题 I am watching Jerry Cain's Programming Paradigms Lecture 3 video where the effect of an element assignment after casting between an int array and short array is demonstrated. Essentially the argument is that if you were to assign an int array element arr[3] = 128 , then temporarily cast the int array to a short* and assign arr[6] = 2 , then arr[3] should become 128 + 512 = 640 because the 2 would be interpreted as being in the 2^9th position. Code to demonstrate: #include <stdio.h> int main()

point of Byte and Short in Java (I've read the other questions)

此生再无相见时 提交于 2019-12-12 21:26:46
问题 My question is: If I got it right from the Java disassembly, when I use byte a=3,b=5; System.out.println(a+b); would actually use int instead of byte. Also all local memory slots are 4B just as stack slots. I realize that allocating a byte array would probably act more efficiently, but is it true that using a single byte value is ultimately inefficient? (The same point for short) 回答1: The first rule of performance tuning should be to write simple, clear code. In this example, there is no

Int16 - bytes capacity in.net?

帅比萌擦擦* 提交于 2019-12-12 08:07:45
问题 Why does : short a=0; Console.Write(Marshal.SizeOf(a)); shows 2 But if I see the IL code i see : /*1*/ IL_0000: ldc.i4.0 /*2*/ IL_0001: stloc.0 /*3*/ IL_0002: ldloc.0 /*4*/ IL_0003: box System.Int16 /*5*/ IL_0008: call System.Runtime.InteropServices.Marshal.SizeOf /*6*/ IL_000D: call System.Console.Write The LDC at line #1 indicates : Push 0 onto the stack as int32 . So there must been 4 bytes occupied. But sizeOf shows 2 bytes... What am I missing here ? how many byte does short actually

Why short* instead of char* for string? Difference between char* and unsigned char*?

喜你入骨 提交于 2019-12-11 15:38:40
问题 As the title says, I'm having two questions. Edit : To clarify, they don't actually use char and short , they ensure them to be 8-bit and 16-bit by specific typedefs. The actual type is then called UInt8 and UInt16 . 1. Question The iTunes SDK uses unsigned short* where a string is needed. What are the advantages of using it instead of char* / unsigned char* ? How to convert it to char* , and what differs when working with this type instead? 2. Question I've only seen char* when a string must

Why is there no String.valueOf(short a);

本小妞迷上赌 提交于 2019-12-11 12:32:27
问题 I had to cast short to a string and the only way I could do it was to concatenate an empty string with it, is this the right way? PS, why is there no String.valueOf(short a) ; 回答1: Because the creators of the JDK didn't think that it is needed. Given a short you can simply call String.valueOf(int) . Note that even Short.toString(short) is implemented as return Integer.toString((int)s, 10); 回答2: You can use short s = 5 String str = String.valueOf(s); // s is widened to int. or String str =

JTextField accept only valid unsigned Shorts? (Using KeyAdapter)

柔情痞子 提交于 2019-12-11 09:51:22
问题 Below is the KeyAdapter I tried to get working to only accept values less than 65535. It seems as though it gets it one keystroke behind where it actually should. For example, If I type "55", the System.out.println will yield "5", doing "3298" will yield "329", etc. // Allows for unsigned short values only KeyAdapter unsignedShortAdapter = new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); int tempInt = 0; JTextField temp = null; if (!((Character.isDigit(c) || (c =

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?

丶灬走出姿态 提交于 2019-12-11 06:04:57
问题 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 do. My question is this: does it make more sense to store this string as a database field on creation of each piece of content, or simply decode the string on

Java On AND'ing a short with an short, it is upgraded to int and returns weird values

馋奶兔 提交于 2019-12-11 02:16:13
问题 I'm creating a mask and setting higher bits in a short like this: enum FLAGS {FLAG1, FLAG2, FLAG3, FLAG4, FLAG5, FLAG6}; public static void setFlag(short len, FLAGS flag) { short mask = 1 << (Short.SIZE - flag.ordinal() - 1); len |= mask; } I printed the values: len: 0000001111111100 mask : 1000000000000000 after OR'ing with mask: 11111111111111111000001111111100 I understand that when we do bit manipulation on shorts they're upgrded to int to avoid overflow, but why are all the higher bits