How to properly generate UUID on Windows Phone 8 - windows-phone-8

I want to generate UUID on a Windows Phone 8 device.
I have used DeviceExtendedProperties to get DeviceUniqueId, which returns a 20 byte array of numbers.
Then I have truncated it to 16 bytes (as in RFC4122 implementation example) and inserted variant (binary 10) and version number (5).
Finally, I initialized System.Guid object, passing my byte array into its constructor. The resulting string representation of System.Guid object is "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx", where M is version (4 bits set to 0 1 0 1) and N is a variant (4 bit number where two most significant bits are set to 1 0).
Is it okay to simply truncate the last 4 bytes from DeviceUniqueId? Do I really need to insert variant and version number? If so, which version number should I use or does it matter which version to use?

Related

How is DECIMAL(m, n) represented in a 64-bit system?

What is the relationship between a DECIMAL(m,n) column specification and the actual representation of that column in a 64-bit MySQL implementation?
I'm defining tables in a context where I know I need an exact value (hence DECIMAL) and I don't know how sensitive I am to truncation errors in the decimal portion. I'd therefore like to choose a column specification that makes reasonable use of the underlying storage (I know it's a 64-bit system).
I haven't yet found an answer in the MySQL documentation despite a reasonable search.
It doesn't matter if you're using a 64-bit MySQL build. DECIMAL supports precision greater than 64 bits.
DECIMAL uses 4 bytes for each 9 digits, plus extra bytes for the leftover digits. For example, DECIMAL(32,0) supports up to 9+9+9+5 digits. It will use 4+4+4 bytes for the first 27 digits, then 3 more bytes for the remaining 5 digits. A total of 12+3, or 15 bytes.
The fractional part of the decimal value (after the decimal point) stores digits similarly. So DECIMAL(32,9) would support up to 9+9+5 digits for the integer portion and another 9 digits for the fractional portion. Thus 4+4+3 bytes for the integer and 4 bytes for the fractional part.
There's a more detailed description with examples down to the byte, in the code comments for the decimal2bin() function here:
https://github.com/mysql/mysql-server/blob/8.0/strings/decimal.cc#L1282-L1343

The "value offset" field of an IFD entry with a rational type can only hold an offset?

Consider an IFD entry with a rational type (UNSIGNED RATIONAL or SIGNED RATIONAL).
A value that has a rational type is 8 bytes.
The "value offset" field is 4 bytes.
Therefore, the "value offset" field of an IFD entry with a rational type can only hold an offset (the field can never hold a value).
Is that correct?
Short version: Yes.
Long version:
The TIFF IFD consists of IFD entries, which again consist of 12 bytes, containing, in order:
2 byte Tag identifier
2 byte Type
4 byte Count
4 byte Value OR Offset
Quoting from the TIFF 6.0 spec:
Value/Offset
To save time and space the Value Offset contains the Value instead of pointing to
the Value if and only if the Value fits into 4 bytes. If the Value is shorter than 4
bytes, it is left-justified within the 4-byte Value Offset, i.e., stored in the lowernumbered
bytes. Whether the Value fits within 4 bytes is determined by the Type
and Count of the field.
So, as the rational types are always at least 8 bytes long, they can never appear as an "inline" value, only as offsets + value somewhere else in the file.

Converting 8 bit binary to BCD using integers

OK hello all , what i am trying to do in VHDL is take an 8 bit binary value and represent it as BCD but theres a catch as this calue must be a fraction of the maximum input which is 9.
1- Convert input to Integer e.g 1000 0000 -> 128
2- Divide integer by 255 then multiply by 90 ( 90 so that i get the one's digit and the first digit after the decimal point to be all after the decimal point)
E.g 128/255*90 = 45.17 ( let this be signal_in)
3.Extract the two digits of 45 by dividing by 20 and store them as separate integers
e.g I would use something like:
LSB_int = signal_in mod 10
Then i would divide signal in by 10 hence changing it to 4.517 then let that equal to MSB_int.. (that would truncate the decimals and store 4 right)
4.Convert both the LSB_int and MSB_int to 4 digit BCD
..and i would be perfect from there...But sadly i got so much trouble...with different data types (signed unsigend std_logic_vectors)and division.So i just need help with any flaws in my thought process and things i should look out for when doing this..
I actually did over my code and thought i saved this one..but i didn't and well i still believe this solution can work i would reply with what i think was my old code...as soon as i could remember it all..
Here is my other question with my new code..(just to show i did do something..)
Convert 8bit binary number to BCD in VHDL
f I understand well, what you need is to convert an 8bit data
0-255 → 0-9000
and represent it with 4 BCD digit.
For example You want 0x80 → 4517 (BCD)
If so I suggest you a totally different idea:
1)
let convert input range in output range with a simple 8bit*8bit->16bit
(in_data * 141) and keep the 14 MSB (0.1% error)
And let say this 14 bit register is the TARGET
2)
Build a 4 digit BCD Up/Down counter (your output)
Build a 14bit Binary Up/Down counter (follower)
Supply both with the same input (reset, clk, UpDown)
(making one the shadow of the other)
3)
Compare TARGET and the binary counter
if (follower < target) then increment the counters
else if (follower > target) then decrements the counters
else nothing
4)
end

AS3- Using 7 byte HEX values as keys in dictionary

I have an AIR application that reads RFID tags. The values of the tag ID's are 7 byte hex values.
There is a limitation on the highest numbers represented accurately within actionscript.
The Number type only works with 53 bit values. The 7byte hex value is 56 bit.
So there is a chance of possibly duplicate keys.
Is there any advantage in using the HEX values themselves as keys for the dictionary?
Or does Flash internally still convert these values to Numbers before using as keys?
You are right about this limitation, as3 Number type is actually a Double precision 64-bit with only 53 bits for the mantissa, but I wonder how do you read the 7 byte value and where do you store it?
There are several as3 Long implementations (64 Integer) so you can use it to read and store 7 bit number (but it will still read 8 bytes from the ByteArray), but if you don't need the Math for your big number just use Strings to read in and use them as a keys for Dictionary.
Anyway Dictionary uses only Strings or Objects as a keys but not Numbers, so even if as3 had a Long it would be convert to the String.

Pascal memory issues

I have a problem that requires searching and saving some values that prevent it from doing an infinite loop. Every possible state of this problem is expressed as an unique 8 digit code with base 6 (all digits are 0-5). When the program evaluates this position, I want a boolean to be set as true so as not to evaluate this position again. However an array 1..55555555 is too large in memory and if i convert the 8 digit code to decimal it takes too much time. Also not all combinations are possible in the problem; 11 11 11 11, 11 11 55 12 and others are not valid and i need not use extra memory. So, is there a way to store as value "true" a block of memory with adress e.g 23451211 and when i call the evaluating process check if 23451211 is true or unassigned;
6 to the power 8 = 1679616.
To mark used or not you need one bit, thus you can do with about 209952 bytes.
In recent Free Pascal's, bitpacked structures are done as follows
var
arr : bitpacked array [0..6*6*6*6*6*6*6*6-1] of boolean;
and arr[x] will give true or false.
The conversion time from base 6 to binary (not decimal!) will probably be shorter than trying to use large swaths of memory. (((digit8)*6+digit7)*6+digit6)*6 etc
p.s. FPC does have an exponent operator, but not for constants, so that's why 6^8 is written like that.