将 Qlikview 十六进制日期转换为正常日期

如何解决将 Qlikview 十六进制日期转换为正常日期

我从 Qlikview 导出了一个 XML 文件,日期采用这种 16 位字母/数字形式(即 40E5A40D641FDB97)。我尝试了多种方法将其转换为浮点小数,然后转换为日期,但所有方法都失败了(包括 Excel HEX2DEC)。

之前有人处理过这个问题吗?非常感谢任何帮助!

解决方法

This reference 显示了如何表示浮点数。在双精度(使用总共 64 位)中,有一个符号位、11 位指数和 53 位有效数或尾数。细心的读者会注意到,总共有 65 位:这是因为尾数中的最高有效位是隐藏位,按照惯例,它始终设置为 1,不必存储。

以第一个例子为例:

enter image description here

我们有

指数

enter image description here

指数是前三个十六进制数字(符号位加 11 位数字 - 但日期的符号位始终为零,因为它们是正数)。它可以使用任何合适的标准方法进行转换,例如在 Excel 365 中:

=LET(L,LEN(A2),seq,SEQUENCE(L),SUM((FIND(MID(A2,1),"0123456789ABCDEF")-1)*16^(L-seq)))

通过从转换后的值中减去 1023(偏移量)得到正确的结果,例如

40E -> 1038

1038 - 1023 -> 15

所以乘数是 2^15。

有效符号

enter image description here

我们需要取字符串右侧的 13 个十六进制数字(52 位),并使用您最喜欢的转换方法将其转换为分数,例如在 Excel 365 中:

=LET(L,"0123456789ABCDEF")-1)*16^(-seq)))

然后你需要加 1(这是隐藏位,它总是设置为 1)。

综合起来:

enter image description here

,

这是一个 Power Query 例程,它将将该十六进制数转换为其等效日期:

我使用查找表并连接结果生成十六进制数的二进制等效项。

算法在编码上要清晰,并遵循IEEE-754规定的规则。

对于您在问题中提到的日期,它提供相同的结果。

请注意,当您从 Qlikview 描述日期表示时,此例程假定编码的有效值。它不是通用例程。

let 

//don't really need the Decimal column
hexConvTable = Table.FromRecords({
    [Hex="0",Dec=0,Bin = "0000"],[Hex="1",Dec=1,Bin = "0001"],[Hex="2",Dec=2,Bin = "0010"],[Hex="3",Dec=3,Bin = "0011"],[Hex="4",Dec=4,Bin = "0100"],[Hex="5",Dec=5,Bin = "0101"],[Hex="6",Dec=6,Bin = "0110"],[Hex="7",Dec=7,Bin = "0111"],[Hex="8",Dec=8,Bin = "1000"],[Hex="9",Dec=9,Bin = "1001"],[Hex="A",Dec=10,Bin = "1010"],[Hex="B",Dec=11,Bin = "1011"],[Hex="C",Dec=12,Bin = "1100"],[Hex="D",Dec=13,Bin = "1101"],[Hex="E",Dec=14,Bin = "1110"],[Hex="F",Dec=15,Bin = "1111"]},type table[Hex = Text.Type,Dec = Int64.Type,Bin = Text.Type]),hexUp = Text.Upper(hexNum),hexSplit = Table.FromList(Text.ToList(hexUp),Splitter.SplitByNothing(),{"hexNum"}),//To sort back to original order
    addIndex = Table.AddIndexColumn(hexSplit,"Index",1,Int64.Type),//combine with conversion table
    binConv =   Table.Sort(
                    Table.Join(
                        addIndex,"hexNum",hexConvTable,"Hex",JoinKind.LeftOuter),{"Index",Order.Ascending}),//equivalent binary
    binText = Text.Combine(binConv[Bin]),sign = Text.Start(binText,//change exponent binary parts to numbers
    expBin = List.Transform(Text.ToList(Text.Middle(binText,11)),Number.FromText),//exponent bias will vary depending on the precision being used
expBias = 1023,//Number.Power(2,10-List.PositionOf(expBin,1))-1,expPwr= List.Reverse({0..10}),exp = List.Accumulate({0..10},(state,current) =>
            state + (expBin){current} * Number.Power(2,expPwr{current})) - expBias,mantBin = List.Transform(Text.ToList(Text.Middle(binText,11,52)),mantPwr = {0..51},mant = List.Accumulate({0..51},current) =>
            state + (mantBin){current} / Number.Power(2,mantPwr{current})) +1,dt = mant * Number.Power(2,exp)
in 
   DateTime.From(dt)
,

您可以在 Qlikview 中使用带有 Num#(将文本转换为数字)和 Num 的标准窗口格式从十六进制转换为 bin :

# example data from inline table in loading script
[our_hex_numbers]:
LOAD
 Num(Num#(hex,'(HEX)'),'(BIN)') as bin
Inline
[hex,'A','B','C'];

结果如下:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res