bigint在二进制(8)列中的二进制表示(Binary representation of bigint into a binary(8) column)
我试图将bigint无符号数字的二进制表示存储到MySql中的二进制(8)列中。 例如,值
9
应该被存储为0...01001
,并且必须填充一堆0
的左边填充。 这可能吗?I'm trying to store the binary representation of a bigint unsigned number into a binary(8) column in MySql. For example, the value
9
should be stored as0...01001
, complete with the obligatory left padding of a bunch of0
s. Is this possible?
原文:https://stackoverflow.com/questions/40982484
最满意答案
minutes: bgt $t1,59,hour ; 1 seconds: bgt $t2,59,minutes ; 2 li $v0, 1 ; 3 : addi $t2,$t2,1 j seconds
当
$t2
最终达到60
,你所拥有的代码段将是一个无限循环。在代码中没有任何地方你实际上将
$t2(secs)
设置回零并增加$t1(mins)
所以,一旦$t2
达到60
并且你跳到seconds
,这里是执行路径:2, 1, 2, 1, 2, ...
,没有机会再次升级到3
。至于如何修复它,不要只是在
$t2
溢出时跳回到minutes
,你必须将$t2
设置回零并增加$t1
。 然后你需要检查$t1
溢出等等。因为它可能是classwork,我只提供伪代码(汇编程序),但是构造代码的最佳方法可能是:
start: $t0 = 0 $t1 = 0 $t2 = -1 loop: $t2 = $t2 + 1 if $t2 < 60 goto skipmin $t2 = 0 ; special when secs -> 60 $t1 = $t1 + 1 skipmin: if $t1 < 60 goto skiphour $t1 = 0 ; special when mins -> 60 $t0 = $t0 + 1 if $t0 == 24 goto end ; stop at 24:00:00 skiphour: display $t0:$t1:$t2 goto loop end: stop program
至于如何使用前导零显示值,再次使用伪代码(仅对于秒值,您将必须将其展开以处理分钟和小时):
if $t2 > 9 goto nozerosec syscall 4 with $a0 pointing at "0" nozerosec: syscall 1 with $a0 loaded from $t2
这只是通过检查您要输出的值来工作,如果它小于10,则首先输出前导零。
这假设(似乎是)syscall 1用于输出
$a0
的值,而syscall 4用于输出$a0
指向的字符串。而且,对于额外的积分,您可以使填充输出成为一个单独的函数来调用,而不是在主程序中重复自己。
minutes: bgt $t1,59,hour ; 1 seconds: bgt $t2,59,minutes ; 2 li $v0, 1 ; 3 : addi $t2,$t2,1 j seconds
When
$t2
eventually gets to60
, that code segment you have there is going to be an infinite loop.Nowhere in the code are you actually setting
$t2(secs)
back to zero and incrementing$t1(mins)
so, once$t2
hits60
and you jump toseconds
, here's the execution path:2, 1, 2, 1, 2, ...
, with no chance of advancing to3
again.As to how to fix it, don't just jump back to
minutes
when$t2
overflows, you have to set$t2
back to zero and increment$t1
. Then you need to check$t1
for overflow and so on.Since it's probably classwork, I'll offer pseudo-code (of an assembler variety) only, but possibly the best way to structure your code would be:
start: $t0 = 0 $t1 = 0 $t2 = -1 loop: $t2 = $t2 + 1 if $t2 < 60 goto skipmin $t2 = 0 ; special when secs -> 60 $t1 = $t1 + 1 skipmin: if $t1 < 60 goto skiphour $t1 = 0 ; special when mins -> 60 $t0 = $t0 + 1 if $t0 == 24 goto end ; stop at 24:00:00 skiphour: display $t0:$t1:$t2 goto loop end: stop program
As to how to display values with leading zeroes, again with pseudo-code (for just the seconds value, you'll have to expand it to handle minutes and hours):
if $t2 > 9 goto nozerosec syscall 4 with $a0 pointing at "0" nozerosec: syscall 1 with $a0 loaded from $t2
This simply works by checking the value you're going to output and, if it's less than 10, outputting a leading zero first.
This is assuming (as it seems to be) that syscall 1 is for outputting a value in
$a0
and syscall 4 is for outputting a string pointed to by$a0
.And, for extra credits, you can make the padded output a separate function to be called rather than repeating yourself in the main program.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
要从内存加载一个值,您需要调用其中一个加载指令( lw , lh或lb表示字,半字和字节)。 例如: lw $a1, 0($a2) # load a word from the address in $a2 + offset 0 to $a1 要在内存中写入值,可以使用其中一个store命令,例如: sw $a1, 0($a2) # store the word in $a1 into the address in $a2 + offset 例如,使用la完成将地址加载到寄存器中 la $a2, lab ...
-
MIPS组装标签(MIPS Assembly Labels)[2022-11-14]
标签只有这样才能引用跳线。 CPU本身只能看到机器代码。 您的代码中的任何注释都是如此。 它们只存在于汇编程序中 - 然后将其转换为机器代码。 如果您不想执行,则需要跳过一行。 Labels are only so you can reference the line with a jump. The CPU itself will only see the machine code. The same is true of any comments in your code. They are only ... -
在POSIX.1-2008中,时钟的保证粒度指定为至少20ms。 这是与密切相关的片段: CLOCK_REALTIME和CLOCK_MONOTONIC时钟的最大允许分辨率以及基于这些时钟的所有时间服务由{_POSIX_CLOCKRES_MIN}表示,并且应定义为20 ms(1/50秒)。 实现可以支持这些时钟的较小分辨率值,以提供更精细的粒度时基。 使用clock_getres()函数获取特定时钟的实现所支持的实际分辨率。 如果基于这些时钟之一的时间服务支持的实际分辨率不同于该时钟支持的分辨率,则实现应记录 ...
-
嵌套循环?(Nested For Loops?)[2022-11-02]
Suggest me any book or paper on for loops or links!! 为了巩固你对循环2的理解,你可以尝试在http://www.codingbat.com/java练习 - 此外,还有即时和(大部分)彻底的评分! String-3或Array-3问题可以使用2 for循环。 如果你有一个2D数组,并且你需要到达所有的索引,你可以使用2 for循环。 因此,类似地,如果你有一个3D数组,你可以使用3个嵌套循环。 请记住,循环内部在外部之前结束 - 因此,如果您有2个循环, ... -
minutes: bgt $t1,59,hour ; 1 seconds: bgt $t2,59,minutes ; 2 li $v0, 1 ; 3 : addi $t2,$t2,1 j seconds 当$t2最终达到60 ,你所拥有的代码段将是一个无限循环。 在代码中没有任何地方你实际上将$t2(secs)设置回零并增加$t1(mins)所以,一旦$t2达到60并且你跳到seconds ,这里是执行路径: 2, 1, 2, ...
-
我认为if((a[i] > 0) && (b[j] > 0))不能在一个分支中完成,因为当第一个操作数为真(非零)时,不能计算&&的第二个操作数。 这是MIPS代码的一个例子,代表if((a[i] > 0) & (b[j] > 0)) count = count + 1; (未测试) # assuming that i = $t2, j = $t3, count = $s4 sll $t4, $t2, 2 # calculate offset of a[i] lw $t5, a($t ...
-
MIPS构造循环(MIPS Constructing Loops)[2024-02-01]
我不确定你在“set counter”部分做了什么,因为s1已经包含了系列成员的数量。 并且s0包含当前元素。 所有你需要的(附加信息)是清除current_sum,让我们说s3 : add $s3, $zero, $zero ; or "move $s3, $zero" if you prefer the pseudo-ops 因此,对于第一个示例[5, 3, 4, 0]在第一次循环迭代之前[5, 3, 4, 0] s0 - s3将设置为[5, 3, 4, 0] s3 [5, 3, 4, 0] 。 ... -
至少有三个错误: 您正在覆盖$t6 ,它应该具有A和C的偏移量与A的基地址 你覆盖$t7 ,它应该保存A [i] [j]的内容,地址为B [j] [i] 您错误地计算了行偏移量。 而不是移动16行时间,你应该移动行4次(这有效地将行乘以16) 你可能会改变 sllv $t6, $t0, $t1 #Row, shift 16 by current counter -> 32 -> 64.. ... addu $t6, $t6, $t3 #Add A base address. lw $t7, ($t6) ...
-
使用mips指令(using mips instructions)[2023-07-17]
基本上,MIPS指令具有存储在最高有效6位中的操作码,其指定后续位的格式。 特别地,R型指令总是具有000000的操作码(其中指令功能由6个最低有效位进一步指定。 MIPS指令编码 Basically MIPS instructions have an opcode stored in the most significant 6 bits which specify the format of the following bits. In particular, R-type instructions a ...