루비를 사용하여 정수 값에서 이진 왼쪽 시프트를 수행하는 방법은 무엇입니까? (자바)루비 이진 왼쪽 시프트
:나는 왼쪽 시프트 이항 연산을 할 노력하고있어하지만 난 이상한 문자 대신 이동의 받고 있어요 ..
는 나는 다음과 같이 수행해야한다고 생각
b = (b >> 2); // 0011 1111
b = (b < < 2); // 1111 1100
내가 루비에서 이런 일을 해요 :
currentRed = ChunkyPNG::Color.r(image[x,y])
currentGreen = ChunkyPNG::Color.g(image[x,y])
currentBlue = ChunkyPNG::Color.b(image[x,y])
binRed = currentRed.to_s.unpack("b*")[0]
binGreen = currentGreen.to_s.unpack("b*")[0]
binBlue = currentBlue.to_s.unpack("b*")[0]
puts "original"
puts "r #{binRed}"
puts "g #{binGreen}"
puts "b #{binBlue}"
puts "------"
binRed = binRed << 2
binGreen = binGreen << 2
binBlue = binBlue << 2
puts "new"
puts "r #{binRed}"
puts "g #{binGreen}"
puts "b #{binBlue}"
을하고하는 것은 점점 :
무엇이 당신의 질문입니까? – sawa
rgb 값을 정수 바이너리 형식으로 변환하는 방법은 무엇입니까? rgb 값을 다음과 같이 바이너리 형식으로 변환 해 보았습니다. binRed = currentRed.to_s (2) \t binGreen = currentGreen.to_s (2) \t binBlue = currentBlue.to_s (2) 그러나 printscreen과 같은 결과가 나타납니다. 위 .. 아직도 문자열 때문에 .. – Alexandre