您好,我是一个学习JavaScript的初学者程序员。当我查看源代码时,我创建了一个带有DataView(缓冲区)的视图,并使用setUint32将值放在位置0。当我再次用Uint32Array加载缓冲区时,为什么值536870912不会更改为32?
var buffer = new ArrayBuffer(76);
var view = new DataView(buffer);
var value = 20000000;
// set value 536807912
view.setUint32(0, parseInt(value, 16));
// [17/05/2019 10:00:20.149] [LOG] getUint32 536870912
console.log('getUint32 ' + view.getUint32(0));
var test = new Uint32Array(buffer);
/* [17/05/2019 10:00:20.150] [LOG] Uint32Array [ 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] */
console.log(test);
答案 0 :(得分:3)
您看到NB=ttk.Notebook(root)
Page1 = ttk.Frame(NB,width=1200,height=500,relief=RIDGE,style='My.TFrame')
NB.add(Page1,text='SOUPS')#,font=('arial',20,'bold')
Page1_1 = Frame(Page1,width=495,height=300,bg='lavender',bd=5,relief=RIDGE)
Page1_1.place(x=5,y=5)
Page1_2 = Frame(Page1,width=695,height=300,bg='lavender',bd=5,relief=RIDGE)
Page1_2.place(x=505,y=5)
Page1_3 = Frame(Page1,width=1195,height=195,bg='lavender',bd=5,relief=RIDGE)
Page1_3.place(x=5,y=305)
Chicken_Soup = Label(Page1_1,text='CHICKEN SOUP',bg='lavender',font = ('arial',10,'bold'),pady=10,width=35,anchor='w',justify=LEFT)#.grid(row=0,column=0)
Chicken_Soup.grid(row=0,column=0)
Label(Page1_1,text='MUTTON SOUP',bg='lavender',font = ('arial',10,'bold'),pady=5,width=35,anchor='w',justify=LEFT).grid(row=1,column=0)
Label(Page1_1,text='CRAB SOUP',bg='lavender',font = ('arial',10,'bold'),pady=5,width=35,anchor='w',justify=LEFT).grid(row=2,column=0)
Label(Page1_1,text='TOMATO SOUP',bg='lavender',font = ('arial',10,'bold'),pady=5,width=35,anchor='w',justify=LEFT).grid(row=3,column=0)
Button(Page1_1,text='hide Chicken',font = ('arial',10,'bold'),width=25,anchor='w',justify=LEFT,command=Hide).grid(row=4,column=0)
Button(Page1_1,text='Unhide chicken',font = ('arial',10,'bold'),width=25,anchor='w',justify=LEFT,command=Unhide).grid(row=5,column=0)
使用32的原因是Endianness。使用Uint32Array
时,DataView
和setUint32
函数具有一个附加参数getUint32
,当被忽略时,默认为big-endian。然后,使用littleEndian
,它将使用系统的字节序,在这种情况下为little-endian。
因此,在Uint32Array
情况下,您将使用big-endian设置值,然后使用little-endian检索该值,从而得出32的值。
为了说明这一点,这是两个使用不同字节顺序的值:
Uint32Array