shift operation with hexadecimal output - hex

I have known till date that %x prints in hexadecimals
Now, when I write printf("%x", -1<<4),the output is fffffff0
But when I write printf("%x", 5<<2), the output is 14
Why does the second output a decimal number?

14 is part of hexadecimal characters set, it's just the result of :
floor(20/16) and 20%16

Related

How to convert hex code to decimal code or vice versa

How can I know what these bunch of hex code means?
02 00 A0 E3 1E FF 2F E1
Any convertor of these codes to decimal code like 1,2,3 etc or vice versa like deciaml code to this type of hex code?
Thanks
This is my first response in stack overflow. So here goes...
What Hex Code (a.k.a. hexadecimal) represents purely depends on its context, or what does it mean to the program or machine. It could be a string, machine code (assembly language), flags, pointers to memory, data, part of an image or whatever. And this is dependent on the processor where this code is located also.
Each 2-digit hex code is a byte and represents decimal number (0-255 or 00-FF), half of a byte or 1 digit hex code is called a nibble.
Converting Hex Code to decimal is trivial. Convert from decimal to hex, not as trivial.
There are many calculators that have this functionality built in.
0-9 => 0 – 9, A=10, B=11, C=12, D=13, E=14, F=15.
Now, if you want to convert a 2 digit number like 12 hex (i.e. 0x12 or 12h ). Here is the formula.
(16 x 1) + (1 x 2) = 18 (decimal)
A four-digit hexadecimal 4A3E =>
(4096 x 4) + (256 x 10) + (16 x 3) + (1 x 14) = 19006 (decimal)
An integer in C# is 4 bytes, so your example hex code could also represent 2 integers in C#. Or it could be simply 1 number in C# called a “long” which is 8 bytes and could represent a number between:
0 to 18,446,744,073,709,551,615 unsigned long OR
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 signed long
Also something to note hex code also represent characters called ASCII (pronounced a·skee) This is an internal mapping within the microprocessor and could be different. 00 is not mapped so it typically means the end of the string.
Hex codes like that could represent a binary number. You could paste "0200A0E31EFF2FE1" into a converter like this to find out that the decimal representation of that number is "144292085413916641", for example.
But, from the way that your hex codes are grouped, it appears that you're looking at binary data, rather than a single integer that's represented in hexadecimal. When hex codes are grouped in pairs, each group of two characters represents one byte. https://en.wikipedia.org/wiki/Hexadecimal#Written_representation

how to print the date in french as follows: Fri 29 Mar 2019 22:53:00

I want to print the date as follows (Ven 29 Mar 2019 22:53:00) but the result is the following (ven. 29 Mar 2019 22:53)
the v is in tiny and there is a point after the ven
I use the following code to get the date in french
Evaluate locale.setlocale(locale.LC_ALL, 'French') locale
this is the syntax I use for formatting:
${startDate} = Get Current Date
result_format =a% d% b% Y% %H:%M
Split the string in two - the first word, and the rest, by using Split String with max_split equal to 1:
${splited}= Split String ${your date string} max_split=1
Remove the dot character, and capitalize the first letter by using python's title() method on the first member of the split:
${first}= Remove String ${splited[0]} .
${first}= Evaluate "${first}".title()
And now combine the title-cased word with the remaining part of the split:
${result}= Catenate ${first} ${splited[1]}
# alternatively Set Variable will also do for a simple case like this
${result}= Set Variable ${first} ${splited[1]}
By the way, I see you also want seconds in your date string, the formatting pattern should be like this in this case:
%a d% b% Y% %H:%M:%S

converting decimal to hex in R

I want to convert a decimal number to hex format in a way that only bit corresponding to that decimal number is set. For example, for input 0, bit 0 should be set and results in
> paste("0x", sprintf("%032x",2^(0)),sep="")
[1] "0x00000000000000000000000000000001"
and for 1, bit one should be set, resulting in
> paste("0x", sprintf("%032x",2^(1)),sep="")
[1] "0x00000000000000000000000000000002"
This works till 30
> paste("0x", sprintf("%032x",2^(30)),sep="")
[1] "0x00000000000000000000000040000000"
but does not work for values larger than that
> paste("0x", sprintf("%032x",2^(32)),sep="")
Error in sprintf("%032x", 2^(32)) :invalid format '%032x'; use format %f, %e, %g or %a for numeric objects
Any idea how to get around this?
I think you're "overloading" the sprintf function. That is, your type is set to "%032x" and then you pass in the value 2^(32) which the function doesn't see as "%032x" so you get an error.
Here's a couple of semi-related questions, but I don't think these would count as exact duplicates:
why causes invalid format '%d in R?
hex to string formatting conversion in python
Why does a 32-bit OS support 4 GB of RAM?

How do I Base64 encode a 2 byte sequence?

I'm given a 2 byte sequence and asked to Base64 encode it:
00000001 00010001
From what I understand you can only encode sequences of 6 bits when working with Base64.
So because 16 bits is not divisible by 6 I'm a little stuck.
The solution I can see is to convert the given 2 byte sequence into a 3 byte sequence so it becomes divisible by 6. But how do I do this without changing the value of the initial sequence?
Basically, you pad it out with zeroes to the next multiple of 6 bits, and pad out the last four-character sequence with =s. Since the last two zero bytes don't make up a full input byte, the decoder knows to ignore them. (The = padding isn't totally necessary, but it's customary to make the end result always a multiple of 4 characters long.)
For instance, the sequence you've got is:
00000001 00010001
Breaking that up into groups of 6, we get:
000000 010001 0001
Pad with zeroes:
000000 010001 000100
Convert to ASCII:
ARE
And pad that out:
ARE=

Is the "e" character used to denote an invalid number in graphics data?

I've got a graphical program that's exporting a data file with numbers such as: -1.33227e-015 and -4.02456e-016.
I've long been perplexed by the "e-" notation. Is it used to denote an invalid number? What sort of valid value can I extract from the above numbers? What are they trying to say?
e means "× 10^". It standard for exponent.
e.g. 1.33227e-015 means 1.33227 × 10-15 and -4.02456e-016 means -4.02456 × 10-16.
See http://en.wikipedia.org/wiki/Scientific_notation#E_notation for detail.
No. It signifies exponential/scientific notation. -4.02456e-016 means -4.02456 divided by 10 to the power 16.
e or E stands for exponent. Just like x10^ (in written mathematics). The number following tells you how far the decimal place is moving, (+ for left, - for right) so your above number:
-1.33227e-015
Becomes:
-.00000000000000133227
While:
-4.02456e-016
Becomes:
-.000000000000000402456
That is scientific notation being used to represent extremely "large" or "small" numbers.

Resources