Julia print function printing array of UInt32 as hexadecimal - julia

When I am printing an array of UInt32 number, Julia's print function is printing it as hexadecimal numbers. It is even displaying in workspace as hexadecimal numbers. Why is it so? And how could I print it in decimal notation?

Such decision is discussed here and here.
For a decimal rapresentation of a v array of UInt32:
print.(v)

Related

Converting integer to floating point number in Delphi

Could someone please explain the below code to me? It takes the Integer and converts it to a Single floating point number but if someone could break this down and elaborate that would be helpful.
singleVar := PSingle(#intVar)^
This doesn't convert the integer to a float. It reinterprets the bytes of the 32-bit integer as a single (a floating point data type that also has 32 bits).
#intVar is the address of the integer data in memory. The type is pointer to integer (PInteger). By writing PSingle(#intVar), you tell the compiler to pretend that it is a pointer to a single; in effect, you tell the compiler that it should interpret the data at this place in memory as a single. Finally, PSingle(#intVar)^ is simply dereferencing the pointer. Hence, it is the "single" value at this location in memory, that is, the original bytes now interpreted as a single.
Interpreting the bytes of an integer as a single doesn't give you the same numerical value in general. For instance, if the integer value is 123, the bytes are 7B00 0000. If you interpret this sequence of bytes as a single, you obtain 1,72359711111953E-43 which is not numerically equivalent.
To actually convert an integer to a single, you would write singleVar := intVar.

Convert binary to decimal in Julia

I'd like to convert binary to decimal in Julia. It looks like parseint() became deprecated.
Is the below method the best way to do this?
julia> parse(Int,"111",2)
7
Are you starting with a string? Then yes, that's the way. If you're just wanting to write a constant in binary, then it's much easier to just use the 0b111 syntax. By default, it constructs an unsigned integer (which is displayed in hexadecimal), but you can easily convert it to a signed integer with Int(0b111).
julia> 0b110111
0x37
julia> Int(0b110111)
55

Why is typeof hex or binary number Uint64 while type of decimal number is Int64?

julia> typeof(-0b111)
Uint64
julia> typeof(-0x7)
Uint64
julia> typeof(-7)
Int64
I find this result a bit surprising. Why does the numeric base of the number determine signed or unsgined-ness?
Looks like this is expected behavior:
This behavior is based on the observation that when one uses unsigned
hex literals for integer values, one typically is using them to
represent a fixed numeric byte sequence, rather than just an integer
value.
http://docs.julialang.org/en/latest/manual/integers-and-floating-point-numbers/#integers
...seems like a bit of an odd choice.
This is a subjective call, but I think it's worked out pretty well. In my experience when you use hex or binary, you're interested in a specific pattern of bits – and you generally want it to be unsigned. When you're just interested a numeric value you use decimal because that's what we're most familiar with. In addition, when you're using hex or binary, the number of digits you use for input is typically significant, whereas in decimal, it isn't. So that's how literals work in Julia: decimal gives you a signed integer of a type that the value fits in, while hex and binary give you an unsigned value whose storage size is determined by the number of digits.

conversion of decimal to hexadecimal in Embedded C

I want to convert decimal number to hexadecimal in Embedded C.
Actually in my project input to controller is decimal which will be subtracted from hexadecimal value, so I need a conversion.
I tried to write it but after converting a number (75 for example) to its hexadecimal equivalent it will be (411). The trouble is that I did not know how to convert a number like 11 to b in hexadecimal as you know that there is no 11 in hexadecimal, it is b; so please help.
I want to save the converted value in a flag (for subtracting), not for printing. I can print a hex value by simple put a condition like:
(if (a > 10) printf("b"))
but this is not a solution for Embedded.
So please give me a complete solution.
I am not sure what you mean but your integer is just the "type of interpretation". In your memory it's just a bunch of 0 and 1, and therefore you can also presentate that "data" in an decimal, hexadecimal way.
If you need it as input for a register, you can just pass it into it.
Or do I missunderstand your problem?

Hex to Ascii conversion problem

What is the ascii representation of this hex value: 0x80487d2 every converter gives me a different answer, hopefully someone can help.
Thanks
0x80487d2 has no ASCII representation.
ASCII can only have characters in the range 0 and 127 (inclusive). The hex value 0x80487d2 is well above 127.
That hex value can be split into multiple bytes but the way this is done depends on whether the machine is little or big endian, and regardless, not all of those bytes have an ASCII representation. You won't find 0xd2 on any ASCII character chart (http://www.asciitable.com/).
Assuming that is a literal number (i.e. not some weird or little-endian encoding) the decimal representation is 134514642.

Resources