tag:blogger.com,1999:blog-87926254414007961.post8165072080412505442..comments2023-06-04T14:14:20.296+03:00Comments on Coder Eye: Java interview question: Count the number of “1” bits in a byteGuy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-87926254414007961.post-71156336164133335472013-02-25T06:45:40.587+02:002013-02-25T06:45:40.587+02:00// shit right 1 bit, including the sign bit
Think ...// shit right 1 bit, including the sign bit<br />Think you mighta missed a letter that heh...Anonymoushttps://www.blogger.com/profile/04366184228431758567noreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-14957212896761036102012-11-11T03:19:07.775+02:002012-11-11T03:19:07.775+02:00Yeah, change this num = (byte)(num >>> 1)...Yeah, change this num = (byte)(num >>> 1); to this num /= 2. Otherwise this code won't work due to sign extension occurring when you shift.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-5234105726343719422012-11-11T02:47:56.205+02:002012-11-11T02:47:56.205+02:00I'm fairly sure your first solution doesn'...I'm fairly sure your first solution doesn't work for negatives either.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-14444072970479598712012-10-09T15:35:01.005+02:002012-10-09T15:35:01.005+02:00Thank you ! =)Thank you ! =)Anonymousnoreply@blogger.com