how to decode an hexacidemal values to binary ones with springboot? - spring

i am a new developper
i don't know how to decode hexacidemal values to binary ones with springboot, Is There a default functions That can help me or should i develop functions by myself
Also ,i want to compare the result with another one , should the 2 values be String ?
thank You

When you group 4 bits(1 bit is binary) it form a tuple which represent by one Hex decimal number.
There is no need of converting Hex to binary(in string format).
If you still want to do this you can refer:
https://www.geeksforgeeks.org/java-program-to-convert-hexadecimal-to-binary/

Related

Generate unique alpha-numeric object ID, like Parse

I already asked what I needed at the title. I want to generate using either PHP or javascript.
I think the class name and some properties are used to build the objectId but someone may already know how its done that could share here?
The Parse Server generates the objectId. It is a randomly generated String of 10 chars length. You can see their implementation at cryptoUtils.newObjectId(). From the code we can conclude that they are not enforcing uniqueness.
https://github.com/ParsePlatform/parse-server/blob/master/src/cryptoUtils.js
Parse is probably using ids generated in Mongodb. They are not random and can be potentially predicted :
A BSON ObjectID is a 12-byte value
consisting of a 4-byte timestamp
(seconds since epoch), a 3-byte
machine id, a 2-byte process id, and a
3-byte counter
http://www.mongodb.org/display/DOCS/Object+IDs

Difference between String Value and Binary Value in Registry

Can someone explain me when to use String Value or Binary Value in windows registry? Is there any security concerns also attached with these or not ?
I want to store date in encrypted format
You must use the binary format. Encrypted data cannot be stored in a string. It will randomly get corrupted when the string is normalized, not every byte value is a valid Unicode codepoint. If you absolutely want a string then you have to encode the data, Convert.ToBase64String().

NumberFormatException while converting from string to integer in servlet

I know ths is a common question here. I have read the solutions and modified the code then also i am not getting the solution so I have posted my code here.
when I read a value from the text box and parse the value into int from String in servlet, why does it show NumberFormatException?
String ph=request.getParameter("phone");
int phone=Integer.parseInt(ph.trim());// exception is generated here
You can't have any characters or symbols in an int AND the maximum size of an int is 2,147,483,647 which means the phone number 555 555 5555 would be to large to store in an int.
Change the parse to a long and it should fix your problem
A good rule to follow is do not store any number like SSN or Phone numbers's in numerical primitives. You want to leave the numerical primitives for values you plan on doing something math related. Keep them as strings if at all possible.
Because the value you are feeding it is not a valid integer. Make sure it doesn't have strange characters in it.
9835008199 is higher then MAXINT, so that's probaly it.
The docs tell me:
Throws NumberFormatException - if the string does not contain a parsable integer.
On another note: do not store phone numbers as integers. You will get in trouble (you are in fact already). Rule of thumb: if you do not want to do math with a number, it's not an int, but a string.
Use isNumber function to check whether it is a valid number.

Compression algorithms for Strings

I have to generate QRCodes using concatenated object properties. These strings might be long, that's why I'd like to know which compression algorithm to use knowing that my String's length is between 25 an 100+ characters
thanks in advance,
Jerec
I am assuming that since you are going to use compression before you store the strings that these QR codes will not be readable by any client, it would have to be an application that you wrote (b/c you are storing character with an unknown encoding, the client won't be able to decode).
Instead of compressing and storing the long string in the QR code, have your application create a URI (like a GUID or a URL) and when your application decodes that URI it looks up all the values (uncompressed) that you wanted to store in the QR code. Then your app can just look up the format in any way it wants.
For example, assuming your persistant storage is an xml file, but it could be anything:
<URI = "http://mydomain.com/790C9704-8C61-435F-991D-CDBB5767AA3D">
<MyElement>14523</MyElement>
<MyElement>67548</MyElement>
...
<MyElement>46167</MyElement>
</URI>
Encoded on QR code: "http://mydomain.com/790C9704-8C61-435F-991D-CDBB5767AA3D", values can then be looked up.
The algorithm used to encode QR codes is dependent on the type of data you encode. See http://www.swetake.com/qr/qr1_en.html.
If you know, for example, that you always have the same number of digits per id and therefor could just string them together without punctuation, you can encode them as purely numeric and you'll use 10 bits for every three characters.
If you need some kind of separator, if you use something in "0-9A-Z $%*+-./:", you'll stay alphanumeric and get 2 characters in 11 bits.
If you give it arbitrary data (note that this includes any lower case: the list above does not include lower case letters) you're going to be using 8 bits per characters.
So numeric only would end up being 60% smaller.

Make UUID shorter (Hex to ASCII conversion)

In my web application one model uses identifier that was generated by some UUID tool. As I want that identifier to be part of the URL I am investigating methods to shorten that UUID string. As it is currently is in hexadecimal format I thought about converting it to ASCII somehow. As it should afterwards only contain normal characters and number ([\d\w]+) the normal hex to ASCII conversion doesn't seem to work (ugly characters).
Do you know of some nice algorithm or tool (Ruby) to do that?
A UUID is a 128-bit binary number, in the end. If you represent it as 16 unencoded bytes, there's no way to avoid "ugly characters". What you probably want to do is decode it from hex and then encode it using base64. Note that base64 encoding uses the characters + / = as well as A-Za-z0-9, you'll want to do a little postprocessing (I suggest s/+/-/g; s/\//_/g; s/==$// -- a base64ed UUID will always end with two equals signs)

Resources