vb.net - reading bits with for loop, I get 7 bits instead of 8, what's the wrong with this code -
outputs: textbox 2 : falsetruetruetruetruetruefalsefalse
textbox 3 : 1111100
my problem why first boolean of "textbox 2" "false" , first integer of "textbox 3" 1 ? "textbox 2" has 8 booleans while "textbox 3" has 7 bits. , apparently, in "textbox 3, first bit not there. have done wrong .. ? commentary has provided in code. please shed light here.
private sub button3_click(sender object, e eventargs) handles button3.click dim array() byte = file.readallbytes("d:\binfile.bin") using memory memorystream = new memorystream(array) using reader binaryreader = new binaryreader(memory) ba1 = new bitarray(array) dim bit_set integer integer = 0 7 'to view 8 bits in boolean format textbox2.text = textbox2.text & ba1.get(i) if ba1.get(i) = false boolean2bits = 0 'end if elseif ba1.get(i) = true boolean2bits = 1 end if 'to collect 8 bits in integer format bit_set = bit_set & boolean2bits if (i = 7) exit end if next 'to view collected bits in text box textbox3.text = bit_set end using end using end sub
simply because assigning value 01111100 integer variable bit_set. of course, integer, leading 0 not significant, gets stripped out automatically, , gets simplified 1111100, because same number after all.
if don't want lose leading 0 display purposes, don't want bit_set of type integer. declare @ dim bit_set string, , leading 0 not disappear.
Comments
Post a Comment