Tutorials/Datatypes/Solutions

From Kx Wiki
Jump to: navigation, search

1. Create a short integer, p.

q)p:32h
q)type p	/ check that it's a short...
-5h
q)`int$p
32i
q)"i"$p
32i
q)6h$p
32i
q)`float$p
32f
q)"f"$p
32f
q)9h$p
32f
q)`date$p
2000.02.02
q)"d"$p
2000.02.02
q)14h$p
2000.02.02
q)string p
"32"

2. Cast a string to a symbol and back again.

q)string`$"hello"
"hello"

3. The kdb+ epoch is 1 Jan 2001:

q)`date$0
2000.01.01

Earlier dates are simply stored as negative numbers:

q)`date$-5
1999.12.27

4. Characters are stored using their ASCII code, and this is what the cast operator returns by default. Use string notation with a capital letter to get the desired result.

q)"i"$"28"		/ ASCII code
50 56i
q)"I"$"28"		/ desired outcome
28i

5. The result is a boolean list. Notice that there is no space between elements in a boolean list. (This is not necessary since they will either be 1 or 0.)

q)x:2 3 5 2 4 7 2 1i
q)x=2
10010010b

But what does the result mean? the = operator compares each element of x to 2. If equal, it returns 1b (true), otherwise it returns 0b (false). The resulting list is the same length as x.

Back to Tutorials

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox