首页 \ 问答 \ bigint在二进制(8)列中的二进制表示(Binary representation of bigint into a binary(8) column)

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 as 0...01001, complete with the obligatory left padding of a bunch of 0s. Is this possible?


原文:https://stackoverflow.com/questions/40982484
更新时间:2022-07-11 13:07

最满意答案

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 to 60, 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 hits 60 and you jump to seconds, here's the execution path: 2, 1, 2, 1, 2, ..., with no chance of advancing to 3 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.

相关问答

更多
  • 要从内存加载一个值,您需要调用其中一个加载指令( 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 ...
  • 标签只有这样才能引用跳线。 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()函数获取特定时钟的实现所支持的实际分辨率。 如果基于这些时钟之一的时间服务支持的实际分辨率不同于该时钟支持的分辨率,则实现应记录 ...
  • 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 ...
  • 我不确定你在“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指令具有存储在最高有效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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)